I need to get only single item, so I used ngIf instead ngFor in template.
Template:
<div *ngIf="item | async">
Id {{ item.id }}
Number {{ item.number }}
</div>
Service:
get(id: number): Observable<Response> {
return this.http
.get(`myApi/id`)
.map(response => response.json());
}
Component:
export class DetailItemPage {
private item: Observable<Object>;
ngOnInit(){
this.getItem(6994);
}
getItem(id){
this.itemProvider.get(id).subscribe(
res => {
this.item = res;
console.log(this.item);
});
}
}
In the console log I see the object correctly.
With that example, I get error:
InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'
But if I remove the async pipe, WORKS. I can see the item id and number. Why? What I am doing wrong?
PS: I used Angular 4.1.3