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