![](/img/trans.png)
[英]Angular error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays
[英]ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables Angular 9
大家好,我有这个错误错误错误:找不到支持“对象”类型的 object“[对象对象]”的不同。 NgFor 只支持绑定到 Iterables
我试过了。json 但它在 angular 9 中不起作用
我的组件.html
<div class="form-group">
<label for="">Ville</label>
<select class="form-control" #hh
(change)="getidregion(hh.value)">
<option></option>
<option *ngFor="let ville of dropDownList"
[value]="ville.id">
{{ville.nomVille}}
</option>
</select>
</div>
我的组件.TS:
dropDownList: [];
responsable = {
id: 0,
nomResponsable: '',
prenomResponsable: '',
emailResponsable: '',
mdpResponsable: '',
img: '',
rib: '',
dtn: '',
region: 0,
ville: 0,
};
methodAPIToGetVilles() {
this.res.getville()
.subscribe((s: any) => {
this.dropDownList = s;
});
}
//methode to get the value off the idville in the option
getidville(id: any): void {
this.responsable.ville = id;
}
curUser: any = this.responsable[0];
我的 API 数据:
"@context": "/api/contexts/Ville",
"@id": "/api/villes",
"@type": "hydra:Collection",
"hydra:member": [
{
"@id": "/api/villes/6",
"@type": "Ville",
"nomVille": "Davidboeuf"
},
{
"@id": "/api/villes/7",
"@type": "Ville",
"nomVille": "Benoitboeuf"
}];
我想你正在尝试做这样的事情:
<div *ngFor="let item of object | keyvalue">
{{item.key}}:{{item.value}}
</div>
这个问题在这里也得到了很好的回答:
如果您使用
*ngFor
,它只支持数据类型为array or iterables
。
在您的变量dropDownList中的场景数据是 object 类型或可能是 null | 不明确的。 因此发生此错误。 在使用该数据之前对其进行控制台。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.