我的组件中有一个反应式表单,我想将touched
每个输入的属性设置为true
. 我当前的代码会这样做,但会引发错误Cannot set property touched of #<AbstractControl> which has only a getter
:
addressForm: FormGroup;
...
this.addressForm = this._fb.group({
street: ["", [<any>Validators.required]],
city: ["", [<any>Validators.required]],
state: ["", [<any>Validators.required]],
zipCode: ["", [<any>Validators.required]],
country: ["", [<any>Validators.required]]
});
...
for (var key in this.addressForm.controls) {
this.addressForm.controls[key].touched = true;
}
如何将touched
每个输入的值设置为true
?