I am getting an error trying to display he results of my service call. The html page has an ngFor with the | async. I can make the call, get the results, but receiving an error when trying to render the page. I know the variable need to be an Observable for the async to work. I am not sure what I am doing wrong and have tried several things. Any insight is appreciated.
Error Message:
Invalid argument '[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]' for pipe 'AsyncPipe'
Variable Definition
public products:Observable<Product[]>;
Call to Service
ngOnInit() {
this.productService.load().subscribe(
data => {
// Set the products Array
this.products = data['_embedded'].products;
},
error => console.log('Could not find product catalog.')
);
}
Service Call
load() {
return this._http.get(`http://localhost:8000/products`).map(response => response.json());
}
HTML
<tbody *ngFor="let product of products | async">
<tr>
<td>{{product.sku}}</td>
<td>{{product.materialNumber}}</td>
<td>{{product.price}}</td>
<td>{{product.baseUom}}</td>
<td>{{product.packageSize}}</td>
<td>{{product.casePack}}</td>
<td>{{product.weight}}</td>
<td>{{product.height}}</td>
</tr>
</tbody>
Data From Call
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…