Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays
There you don't need to use this.requests=
when you are making get
call(then requests
will have observable subscription). You will get a response in observable success
so setting requests
value in success make sense(which you are already doing).
this._http.getRequest().subscribe(res=>this.requests=res);
Remove this.requests
from
ngOnInit(){
this.requests=this._http.getRequest().subscribe(res=>this.requests=res);
}
to
ngOnInit(){
this._http.getRequest().subscribe(res=>this.requests=res);
}
this._http.getRequest()
returns a subscription, not the response value.
The response value is assigned by the callback passed to subscribe(...)
You can declare the books (on line 2) as an array:
title: any = 'List of books are represted in the bookstore';
books: any = [];
constructor(private service: AppService){
}
ngOnInit(){
this.getBookDetails();
}
getBookDetails() {
this.service.getBooks().subscribe(books => {
this.books = books.json();
console.log(this.books);
});
}