我有一个表单,它将使用异步数据绑定formArray
ngOnInit() {
this.bindNewRequestControls();
}
bindNewRequestControls() {
this.alertSuppressionRequestForm = this.formbuilder.group({
formAppplications: this.formbuilder.array(this.dynamicControls())
})
}
dynamicControls() {
const _dynamiccontrols = [];
for (var i = 0; i < this.data.length; i++) {
_dynamiccontrols.push(this.formbuilder.group({
selectrow: [''],
todate: [''],
fromdate: [''],
changeRequest: [''],
justification: ['']
}))
}
return _dynamiccontrols;
}
现在,在上面的代码中, this.data 是将像这样异步添加的数据
applicationDropdownChange(data?: string) {
this.service.post('url', 'request')
.subscribe(success => {
this.data=success;
});
}
现在,当我将此变量与异步数据绑定时,会出现这样的错误
但是当我在ngOninit()事件上静态传递数据时,thingthign正常工作,我该如何克服呢?谢谢