https://www.concretepage.com/angular-2/angular-2-4-formbuilder-example

уйста, помогите, у меня есть вложенный массив форм, как показано ниже:

  this.form = this.formBuilder.group({
        projectTitle: ['', [Validators.required, Validators.maxLength(300)]],
        projectDescription: ['', [Validators.required, Validators.maxLength(300)]],
        funding: this.formBuilder.array([this._buildFundingItems()]),
    });

this._buildFundingItems() составляет

        private _buildFundingItems(): FormGroup {
          return this.formBuilder.group({
          items: ['', [Validators.required, Validators.pattern(this.regexValidation.shortWordRegex)]],,
          amount: ['', [Validators.required, Validators.pattern(this.regexValidation.amountTypeRegex)]],
        });
     }


    // after reloading the page, i get data from api and I tried setting the value as follows 
    this.form.setControl('funding', this.formBuilder.array(data.funding || []));

делать выше илиthis.form.setControl('funding', this.formBuilder.array(data.funding || [])); я получаю ошибку:Cannot find control with path: 'funding -> 0 -> amount' а такжеCannot find control with path: 'funding -> 0 -> items'.

До того, как я сделал следующее ниже, я не получал никаких ошибок, но при обновлении формы или (на valuechanges), formarray не обновлялся.

     let length: number = data[0].funding.length;
     while (length-- > 0) {
         fundingSupport.push(this._buildFundingItems()); 
     }

     this.form.controls['funding'] = this.formBuilder.array([]);                   
     this.form.controls['funding'].patchValue(data.funding)

Я видел следующую ссылкуAngular 4 patchValue на основе индекса в FormArray Вот почему я попробовал первый подход.

Ответы на вопрос(1)

Ваш ответ на вопрос