用 angular 7 显示 json 数据
Display json data with angular 7
我想在屏幕上显示 json 数据 Angular 7. 我有一个错误。
Cannot find a differ supporting object '[object Object]' of type
'object'. NgFor only supports binding to Iterables such as Arrays.
为我服务;
getData(): Observable <any> {
return this.http.get(this.myUrl);
}
在我的组件中;
public data: []= null;
ngOnInit() {
this.myService.getData().subscribe((d) => this.data = d);
}
在我的 html;
<tbody>
<tr *ngFor = "let people of data">
<td> {{ people.name}}</td>
</tr>
</tbody>
我的json;
{
"people": [
{
"number": [
0,
0
],
"name": "arya"
},
{
"number": [
1,
1
],
"name": "arya2"
}
]
}
如何在 html 屏幕上显示 json 中的这些数据?
用空数组初始化变量 data
。
public data: [] = [];
并将 d.person
分配给 data
变量。
this.myService.getData().subscribe((d) => this.data = d.people);
我想在屏幕上显示 json 数据 Angular 7. 我有一个错误。
Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
为我服务;
getData(): Observable <any> {
return this.http.get(this.myUrl);
}
在我的组件中;
public data: []= null;
ngOnInit() {
this.myService.getData().subscribe((d) => this.data = d);
}
在我的 html;
<tbody>
<tr *ngFor = "let people of data">
<td> {{ people.name}}</td>
</tr>
</tbody>
我的json;
{
"people": [
{
"number": [
0,
0
],
"name": "arya"
},
{
"number": [
1,
1
],
"name": "arya2"
}
]
}
如何在 html 屏幕上显示 json 中的这些数据?
用空数组初始化变量 data
。
public data: [] = [];
并将 d.person
分配给 data
变量。
this.myService.getData().subscribe((d) => this.data = d.people);