【发布时间】:2021-01-09 12:47:47
【问题描述】:
这个 Angular 代码不允许我显示数组。控制台中的错误显示“尝试区分'[object Object]'时出错” 我的 component.ts :
sprints : Sprint[] = [];
ngOnInit() : void {
this.sprintService.getSprints().subscribe(
data =>
{
console.log(data);
this.sprints = data as any;
}
);
}
```
this is html code :
```
<div *ngFor="let sprint of sprints">
{{sprint.codeSprint}}
{{sprint.title}}
</div>
```
I got this error :
ERROR 错误:尝试比较“[object Object]”时出错。只允许使用数组和可迭代对象 在 DefaultIterableDiffer.diff (core.js:26690)
When i logged I got the array but it deosn't diplay in html page
Thanks in advance !
【问题讨论】:
-
您能否提供您在日志记录中看到的确切数据?另外你为什么使用
data as any?为什么是any? -
@Silvermind {code: 3, message: null, object: Array(20)} code: 3 message: null objet: (20) [Array(4), Array(4), Array( 4)、数组(4)、数组(4)、数组(4)、数组(4)、数组(4)、数组(4)、数组(4)、数组(4)、数组(4)、数组( 4), 数组(4), 数组(4), 数组(4), 数组(4), 数组(4), 数组(4), 数组(4)] proto: 对象跨度>
-
您不能将
data分配给您的sprint数组吗?使用data as any的目的是什么? -
对不起,我忘记了,因为在我使用我的 sprints 数组之前,像这样:sprints : any[] = [];
-
所以
data不是数组,但data.objet是。你知道现在该做什么了吗?
标签: angular