![](/img/trans.png)
[英]Cannot find a differ supporting object '[object Object]' of type 'object' in angular 6
[英]Cannot find a differ supporting object '[object Object]' of type 'object' , but it's already an array
我有从后端获取数据到数组的方法
这是方法
getUtilities(): void {
// DropdownHelpers.fillDropdownOptions(
// this._propertyService.getMarketingInformationUtilityTypes(),
// this.utilities
// );
this._propertyService.getMarketingInformationUtilityTypes().subscribe(result => {
this.utilities = result.items;
console.log(this.utilities);
});
}
这是我在控制台中看到的
但是当我尝试做*ngFor="let utility of utilities"
我有
MarketingEditComponent.html:38 错误错误:找不到支持“对象”类型的 object“[对象对象]”的不同对象。 NgFor 仅支持绑定到 Iterables,例如 Arrays。
我的问题在哪里? 数据正在返回数组
this.utilities
可能在 API 调用之前未定义 - 当时它不是一个数组。
解决方案:
*ngIf
以检查它是否是模板中的数组。或者
this.utilities = [];
当您定义实用程序时,将其声明为
公用事业:任何; 或实用程序:any = [];
并在您使用 *ngIf 之前迭代类似
<div *ngIf="utilities">
<div *ngFor="let util of utilities">
{{util.OptionDto.name}} {{util.OptionDto.id}}
</div>
</div>
他们之前所说的没有什么新东西。 如果您仍然感到困惑,请给我一个堆栈闪电战。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.