【发布时间】:2021-02-15 13:59:05
【问题描述】:
我有这个表单组
this.form = this.fb.group({
id: [null],
nome: [null, [Validators.maxLength(60), Validators.required]],
cpf: [null, [Validators.required]],
email: [null, [Validators.required, Validators.maxLength(100)]],
telefone: [null, [Validators.maxLength(14)]],
celular: [null, [Validators.maxLength(14)]],
dataInclusao: [null],
dataDesligado: [null],
gruposEconomicos: [null]
});
而gruposEconomicos 是一个对象数组。我想在mat-select 中检索这个数组,但我收到了这条消息
ERROR Error: Cannot find a differ supporting object 'true' of type 'boolean'. NgFor only supports binding to Iterables such as Arrays.
这就是我尝试循环遍历 this.form.gruposEconomicos 的方式:
<div fxLayout="row" fxLayoutAlign="start center" class="mt-24">
<mat-form-field appearance="outline" fxFlex="30">
<mat-label>Grupo Econômico</mat-label>
<mat-select [(value)]="grupoEconomicoId" (change)="handleGroupChange($event.target.value)">
<option *ngFor="let group of form.get('gruposEconomicos').pristine" [ngValue]="group.id">{{ group.nome }}</option>
</mat-select>
</mat-form-field>
</div>
我也试过了:
<option *ngFor="let group of form.controls.gruposEconomicos" [ngValue]="group.id">{{ group.nome }}</option>
【问题讨论】:
标签: angular typescript ngfor formgroups