找不到其他支持对象"[object Object]" [英] Cannot find a differ supporting object '[object Object]'

查看:111
本文介绍了找不到其他支持对象"[object Object]"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在FormArray中有一个select标记,并且已经使用api中的http来获取该选择的选项.我有以下错误帮助我.

I have a select tag inside my FormArray and i have fetched option for that select using http from the api. I have following error help me.

CashPluckingLeafComponent.html:44错误错误:找不到其他内容类型为对象"的支持对象"[对象对象]".仅NgFor支持绑定到数组等Iterable.

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中(成绩)

grades contain from console.log(grades)

(2)[对象,对象]0:对象1:对象长度:2

(2) [Object, Object] 0: Object 1: Object length: 2

推荐答案

您遇到的问题是名称重叠.要迭代的数组与要在模板中迭代的表单数组中的每个表单对象具有相同名称:

The problem you have is that you have overlapping names. The array you want to iterate has the same name as each form object in your form array that you are iterating in your template:

<div *ngFor="let grades of cplForm.controls.leaf_grade.controls; let i=index">

因此,现在在您的模板中,Angular正在尝试迭代表单组 等级,而不是您的数组等级>.您需要重命名,例如,表单数组的迭代...

So now in your template Angular is trying to iterate the form group grades instead of your array of grades. You need to rename either, for example the iteration of the form array...

<div *ngFor="let gradesGroup of cplForm.controls.leaf_grade.controls; let i=index">

这篇关于找不到其他支持对象"[object Object]"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆