更新时间:2022-12-10 10:51:35
如果您在formGroup
上使用setValue
,但没有为该组中的每个控件传递值,则可能会出现此错误.例如:
This error can appear if you're using setValue
on a formGroup
but not passing in a value for every control within that group. For example:
let group = new FormGroup({
foo: null,
bar: null
});
group.setValue({foo: 'only foo'}); //breaks
group.setValue({foo: 'foo', bar: 'bar'}); //works
如果您确实只想更新组中的控件的 some ,则可以使用patchValue
代替:
If you truly want to only update some of the controls on the group, you can use patchValue
instead:
group.patchValue({foo: 'only foo, no problem!'});
setValue
和patchValue
的文档此处