首页 > 解决方案 > Angular FormArray 未显示其任何 formControl

问题描述

我的 FormArray(反应形式)在前端没有显示任何内容,我在控制台中也没有出现任何错误,而如果我通过 formarray 登录,我可以看到它的值

我被困了将近两天:(我看过十几个关于反应形式的formarrays的视频,但没有一个对我有用

我的 .ts

this.formGroupMail = this.fb.group({
      email: this.fb.array([this.addEmailGroup()])
    });

    // this loops the mails coming from the service
    this.mailForm = this.formGroupMail.get('email') as FormArray;
    if (this.route.snapshot.data['value'].mails !== undefined) {
      for (const c of this.route.snapshot.data['value'].mails) {
        this.mailForm.push(this.fb.group({descripcion: new FormControl(c.descripcion),
                                          isCc: new FormControl(c.isCc),
                                          isCco: new FormControl(c.isCco)}));

      }
    }

  addEmailGroup() {
    return this.fb.group({
      descripcion: [],
      isCc: [],
      isCco: []
    });
  }

  get mailArray(){
    return this.formGroupMail.get('email') as FormArray;
  } 

我的html:

<form [formGroup]="formGroupMail">
          <ng-component formArrayName="email">
            <div *ngFor="let group of mailArray.controls; let i = index" [formGroupName]="i">
              <div fxLayout="row" fxLayoutGap="0.7rem">
                  <mat-label>E-mail</mat-label>
                  <input formControlName="descripcion" type="text" class="form-control" 
                    placeholder="Email"/>
              </div>
            </div>
         </ng-component>
    </form>

标签: angularangular-materialangular-reactive-formsformarray

解决方案


推荐阅读