如果想要获取
FormGroup或FormArray所有的值, 包括disabled元素,应该使用getRawValue()。
因为.value返回的是非disabled状态的元素的值。
const group = new FormGroup({
groupName: new FormControl('CCB'),
members: new FormArray([
new FormGroup({ name: new FormControl('Lorie') }),
new FormGroup({ name: new FormControl('Corey') }),
]),
});
value: anygroup.get('groupName').disable(); console.log(group.value); // will miss groupName (group.get('members') as FormArray).at(0).disable(); console.log(group.get('members').value); // will miss first linegetRawValue(): anygroup.getRawValue(); group.get('members').getRawValue();

在Angular中,当处理FormGroup时,若要获取包括disabled状态输入元素在内的所有值,应当使用formGroup.value。因为formGroup.getRawValue()只会返回非disabled状态的字段。

901

被折叠的 条评论
为什么被折叠?



