我的 Angular 5 / Angular Material 应用程序中有这个 FormArray:
this.form = new FormGroup({
customerNumberContainers: new FormArray([
new FormGroup({
contactTenant: new FormControl('', [Validators.required, Validators.minLength(2)]),
customerNumber: new FormControl('', [Validators.required, Validators.minLength(2)])
}),
]),
...
其实我不知道如何运行这个FormArray。我试过这个
<form [formGroup]="form" (ngSubmit)="onSubmit()">
<div formGroupName="customerNumberContainers">
<div *ngFor="let customerNumberContainer of form.controls['customerNumberContainers']; index as i">
<mat-input-container class="full-width-input" style="min-width:100px;">
<input matInput placeholder="Tenant" formControlName="customerNumberContainer[i].contactTenant">
</mat-input-container>
<mat-input-container class="full-width-input" style="min-width:100px;">
<input matInput placeholder="Customernumber" formControlName="customerNumberContainer[i].customerNumber">
</mat-input-container>
</div>
</div>
...