Angular2 rc6
我有一个动态表单,单击按钮并添加字段。表格开头是空的。该按钮每行添加4个输入字段。因此,如果我单击按钮3次,我将分别获得3行4列。
这些案例起作用:
这是我收到错误的地方:
如果我添加一行输入数据那么添加另一行我得到以下错误:
core.umd.js:5995 EXCEPTION: Error in
app/model_exposure_currencies/model_exposure_currencies.component.html:
33:27 caused by: Expression has changed after it was checked.
Previous value: 'true'. Current value: 'false'.
我只是在进行必要的验证。
以下是相关的ts代码:
cityArray = new FormArray([]);
myForm:FormGroup;
constructor(
private fb: FormBuilder
) {
this.myForm = new FormGroup({
cities: this.cityArray
});
}
onAddRow(name){
for (var _i = 0; _i < this.available_loop.length; _i++) {
this.cityArray.push(new FormControl(name+String(_i+1),[Validators.required]));
}
}