Error when using setControl or patchValue in angular form array

前端 未结 3 1885
终归单人心
终归单人心 2021-01-23 19:21

Please assist, I have nested form array, se below :

  this.form = this.formBuilder.group({
        projectTitle: [\'\', [Validators.required, Validators.maxLengt         


        
3条回答
  •  春和景丽
    2021-01-23 20:17

    Try something like this:

    this.form = this.formBuilder.group({
      projectTitle: ['', [Validators.required, Validators.maxLength(300)]],
      projectDescription: ['', [Validators.required, Validators.maxLength(300)]],
      funding: this.formBuilder.array([this._buildFundingItems({ items: null, amount: null })]),
    });
    
     _buildFundingItems(data): FormGroup {
      if (!data) {
          data = {
            items: null,
            amount: null
          }
      } 
      return this.formBuilder.group({
            items: [data.items, [Validators.required, Validators.pattern(this.regexValidation.shortWordRegex)]],
          amount: [data.amount, [Validators.required, Validators.pattern(this.regexValidation.amountTypeRegex)]],
         })
    
    }
    

提交回复
热议问题