我看过类似的问题,但没有一个对我有帮助。我将收到如下对象:
{
"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());
最后,在i中,我以这种方式调用了服务:
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>
不幸的是,页面加载时抱怨:
找不到类型为“对象”的其他支持对象“ [对象对象]”。 NgFor仅支持绑定到数组等Iterable。
那么,这段代码怎么了?