如何在异步数据上绑定Reactive FormArray?

时间:2019-03-20 08:32:20

标签: angular asynchronous angular6 angular-reactive-forms formarray

我有一个表单,它将使用异步数据绑定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;
      });
  }

现在,当我将此变量与异步数据绑定时,会出现这样的错误

enter image description here

但是当我在ngOninit()事件上静态传递数据时,thingthign正常工作,我该如何克服呢?谢谢

0 个答案:

没有答案