【发布时间】:2018-06-25 07:22:55
【问题描述】:
我正在使用 API 来获取数据并将其绑定到 HTML,我可以在控制台上显示响应,但是一旦我尝试将数据绑定到用户屏幕我就不能,什么都没有显示
我的 HTML:
<ul *ngFor="let item of items; let i of index">
<li class="fa fa-plus">{{item.name}} - {{i}}</li>
</ul>
我的 TS:
id: number;
name:string;
imageUrl: string;
items:any = {};
ngOnInit() {
this.getItems();
}
getItems() {
this.getItemsService.getItems().subscribe(
res => {
console.log(res)
if (res.Success) {
this.items = res;
}
}
)
}
我正在尝试从对象数组中获取数据,这就是为什么我将项目定义为对象,如果我尝试将其定义为数组,同样的结果,无法将数据绑定到 HTML
我的 API 链接:
http://5a12745f748faa001280a746.mockapi.io/v1/stores/item
如有任何问题或缺少的信息,请告诉我,但我需要帮助绑定这些数据
【问题讨论】:
-
项目:任何 = [];改成这个
-
这不会纠正他的问题。
-
并且让 i = index 也适用于 index
-
尝试使用
{{items | json}}只是为了检查模板中是否有值,另外请发布您的console.log返回什么 -
问题已解决,感谢您的帮助^_^
标签: javascript arrays angular typescript get