[英]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.