[英]Cannot find a differ supporting object '[object Object]' of type 'object'
I am working on angular 2 application, in my current project I am getting the data from my API and It's gives the JSON like below. 我正在开发angular 2应用程序,在我当前的项目中,我从我的API获取数据,它给出了如下的JSON。
{
"makes": null,
"models": null,
"trims": null,
"years": null,
"assetTypes": {
"2": "Auto",
"3": "Motorcycle"
}
}
Next I am converting the JSON data to typescript using json2ts tool from this link http://json2ts.com/ 接下来我将使用json2ts工具将JSON数据转换为typescript来自此链接http://json2ts.com/
Typescript.ts Typescript.ts
export interface AssetTypes {
2: string;
3: string;
}
export interface RootObject {
makes?: any;
models?: any;
trims?: any;
years?: any;
assetTypes: AssetTypes;
}
Then After I will use below lines of code In my component.ts 然后我将在我的component.ts中使用下面的代码行
lookupdetailsassettypeinfo: RootObject;
this._vehicleInfoService.getLookupDetailsTableAssetTypeInfo()
.subscribe(lookupdetailsinfo => this.lookupdetailsassettypeinfo = lookupdetailsinfo,
error => this.error = <any>error);
But when I am using the lookupdetailsassettypeinfo in my component.html like this below. 但是,当我用我component.html这样下面的lookupdetailsassettypeinfo。 it always gives the exception like Cannot find a differ supporting object '[object Object]' of type 'object'.
它总是给出异常,例如找不到'object'类型的不同支持对象'[object Object]'。 NgFor only supports binding to Iterables such as Arrays.
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>
Can you please tell me how to resolve the above exception. 你能告诉我如何解决上述异常吗?
-Pradeep -Pradeep
*ngFor
doesn't support iterating over object properties. *ngFor
不支持迭代对象属性。 It only supports arrays. 它只支持数组。
See also Access Typescript Object Variables in Angular2 另请参阅Angular2中的Access Typescript对象变量
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.