[英]Cannot find a differ supporting object '[object Object]' of type 'object'
我正在開發angular 2應用程序,在我當前的項目中,我從我的API獲取數據,它給出了如下的JSON。
{
"makes": null,
"models": null,
"trims": null,
"years": null,
"assetTypes": {
"2": "Auto",
"3": "Motorcycle"
}
}
接下來我將使用json2ts工具將JSON數據轉換為typescript來自此鏈接http://json2ts.com/
Typescript.ts
export interface AssetTypes {
2: string;
3: string;
}
export interface RootObject {
makes?: any;
models?: any;
trims?: any;
years?: any;
assetTypes: AssetTypes;
}
然后我將在我的component.ts中使用下面的代碼行
lookupdetailsassettypeinfo: RootObject;
this._vehicleInfoService.getLookupDetailsTableAssetTypeInfo()
.subscribe(lookupdetailsinfo => this.lookupdetailsassettypeinfo = lookupdetailsinfo,
error => this.error = <any>error);
但是,當我用我component.html這樣下面的lookupdetailsassettypeinfo。 它總是給出異常,例如找不到'object'類型的不同支持對象'[object Object]'。 NgFor僅支持綁定到諸如Arrays之類的Iterables。
<select id="ASSET_TYPE" class="col-md-12 form-control" >
<option>Select One</option>
<option *ngFor='let type of lookupdetailsassettypeinfo'>{{type.assetTypes.Customer}}</option>
</select>
你能告訴我如何解決上述異常嗎?
-Pradeep
*ngFor
不支持迭代對象屬性。 它只支持數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.