【发布时间】:2019-11-19 23:45:04
【问题描述】:
我正在尝试显示从我的端点接收到的一些数据。将其打印到控制台日志可以正常工作,但我无法在 HTML 页面上显示它,即页面为空白。我试过了
<ul>
<li *ngFor="let animal of animals | async">
{{ animal }}
</li>
</ul>
这就是我设置组件的方式:
export class PageComponent implements OnInit {
animals : Animals [];
constructor(private store: Store) { }
ngOnInit() {
this.store.dispatch(fetchUsers).subscribe(animals => {
this.animals = animals ;
console.log(this.animals );
});
}
}
在控制台中,我正在获取从端点接收的 JSON:
animals :
animals : Array(1)
0: {id: "1562", animalType: "dog"}
我希望它返回动物对象,但稍后我将让它打印animalType
【问题讨论】:
-
在 HTML 中输入
{{ animal | json }}或{{ animal.animalType }} -
还是空白:/
-
看起来有一个额外的
animals顶级属性。请使用您的 API 调用结果的 JSON 表示来编辑您的问题。 -
使用
<li *ngFor="let animal of animals">