找不到不同的支持对象“[object Object]”
Cannot find a differ supporting object '[object Object]'
我的 FormArray 中有一个 select 标签,我已经使用来自 api 的 http 获取了 select 的选项。我有以下错误帮助我。
CashPluckingLeafComponent.html:44 ERROR Error: Cannot find a differ
supporting object '[object Object]' of type 'object'. NgFor only
supports binding to Iterables such as Arrays.
<div formArrayName="leaf_grade">
<div *ngFor="let grades of cplForm.controls.leaf_grade.controls; let i=index">
<div [formGroupName]="i">
<div class="form-group">
<label>Leaf Grade {{i + 1}}</label>
<select name="grade" formControlName="grade" class="form-control" id="grade">
<option *ngFor='let lg of grades' [value]="lg.name">{{ lg.name }}</option>
</select>
<small *ngIf="!cplForm.controls.leaf_grade.controls[i].controls.grade.valid && cplForm.controls.leaf-grade.controls[i].controls.grade.touched">
Leaf Grade is required
</small>
<div>
<span *ngIf="cplForm.controls.leaf_grade.controls.length > 1" class="remove-form-control">
<a (click)="removeGradeData(i)">
<i class="fa fa-times fa-fw" aria-hidden="true"></i> Remove
</a>
</span>
</div>
</div>
</div>
</div>
</div>
成绩 包含来自 console.log(成绩)
(2) [对象,对象]
0:对象
1:对象
长度:2
您遇到的问题是名称重叠。您要迭代的数组与您在模板中迭代的表单数组中的每个表单对象具有相同名称:
<div *ngFor="let grades of cplForm.controls.leaf_grade.controls; let i=index">
所以现在在你的模板中 Angular 正在尝试迭代 表单组 grades
而不是你的 数组 的 grades
。您需要重命名,例如表单数组的迭代...
<div *ngFor="let gradesGroup of cplForm.controls.leaf_grade.controls; let i=index">
我的 FormArray 中有一个 select 标签,我已经使用来自 api 的 http 获取了 select 的选项。我有以下错误帮助我。
CashPluckingLeafComponent.html:44 ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
<div formArrayName="leaf_grade">
<div *ngFor="let grades of cplForm.controls.leaf_grade.controls; let i=index">
<div [formGroupName]="i">
<div class="form-group">
<label>Leaf Grade {{i + 1}}</label>
<select name="grade" formControlName="grade" class="form-control" id="grade">
<option *ngFor='let lg of grades' [value]="lg.name">{{ lg.name }}</option>
</select>
<small *ngIf="!cplForm.controls.leaf_grade.controls[i].controls.grade.valid && cplForm.controls.leaf-grade.controls[i].controls.grade.touched">
Leaf Grade is required
</small>
<div>
<span *ngIf="cplForm.controls.leaf_grade.controls.length > 1" class="remove-form-control">
<a (click)="removeGradeData(i)">
<i class="fa fa-times fa-fw" aria-hidden="true"></i> Remove
</a>
</span>
</div>
</div>
</div>
</div>
</div>
成绩 包含来自 console.log(成绩)
(2) [对象,对象] 0:对象 1:对象 长度:2
您遇到的问题是名称重叠。您要迭代的数组与您在模板中迭代的表单数组中的每个表单对象具有相同名称:
<div *ngFor="let grades of cplForm.controls.leaf_grade.controls; let i=index">
所以现在在你的模板中 Angular 正在尝试迭代 表单组 grades
而不是你的 数组 的 grades
。您需要重命名,例如表单数组的迭代...
<div *ngFor="let gradesGroup of cplForm.controls.leaf_grade.controls; let i=index">