【发布时间】:2018-08-10 17:02:57
【问题描述】:
我的 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>
...
【问题讨论】:
-
您是否考虑过创建一个自定义组件来实现 ControlValueAccessor 来处理数组修改?
标签: angular angular-material formarray