我查看了类似的问题,但没有一个对我有帮助。我将收到如下对象:
{
"batch": "1"
"batchsize": "212"
"bmrnumber": "23232"
"fieldname": "Batch"
"id": 5122315436163072
"pelletsize": "1"
"project": "test"
}
我的 http 服务接收它:
this.http.get('/api/getbatch/' + this.authService.namespace + '/' + ID, options)
.map(res => res.json());
最后,在我以这种方式调用服务:
getbatches: any = [];
constructor(private batchServce:BatchService){}
ngOnInit(){
this. this.testbatch();
}
testbatch() {
this.batchServce.getbatch(this.batchID).subscribe(res => {
this.getbatches = res.json();
console.log('-====>' + JSON.stringify(this.getbatches));
});
}
接收显示为表格格式的 HTML 组件:
<table id="Batch">
<tr *ngFor="let batchvalues of getbatches ;let i = index;">
<td><tr>
<th>Product Name</th>
<td> {{batchvalues.product}}</td>
</tr>
</table>
不幸的是,当页面加载时它抱怨:
找不到“object”类型的不同支持对象“[object Object]”。NgFor 仅支持绑定到 Iterables,例如 Arrays。
那么,这段代码出了什么问题呢?