[英]ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables Angular 9
hello every one i have this error ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'.大家好,我有这个错误错误错误:找不到支持“对象”类型的 object“[对象对象]”的不同。 NgFor only supports binding to Iterables
NgFor 只支持绑定到 Iterables
i tried.json but it s not working in angular 9我试过了。json 但它在 angular 9 中不起作用
My component.html我的组件.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>
My Component.TS:我的组件.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];
My API Data:我的 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"
}];
I suppose you are trying to do something like this:我想你正在尝试做这样的事情:
<div *ngFor="let item of object | keyvalue">
{{item.key}}:{{item.value}}
</div>
This questions is also answered pretty nicely here:这个问题在这里也得到了很好的回答:
Iterate over object in Angular 在 Angular 中迭代 object
How to loop over object properties with ngFor in Angular 如何在 Angular 中使用 ngFor 循环 object 属性
If you are using
*ngFor
, it only supports data is of typearray or iterables
only.如果您使用
*ngFor
,它只支持数据类型为array or iterables
。
In your scenario data in your variable dropDownList is either of type object or may be null |在您的变量dropDownList中的场景数据是 object 类型或可能是 null | undefined.
不明确的。 Hence this error occur.
因此发生此错误。 Console that data before using it.
在使用该数据之前对其进行控制台。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.