I'm using Angular 2 and trying to do some filtering on the array elements before viewing them on the page. The service returns the list of some players with this call:
getPlayers(position: string) {
return this.get(`players/${position}`)
.map(r => Observable.from(r.data))
.catch(error => {
console.log('Error: ', error);
return Observable.of<any>();
});
}
As far as I can tell, this returns an ArrayObservable object.
This is how I consume the service in the component:
this.svc.getPlayers(this.position)
.subscribe(p => this.players = p); // this.players is Array<Player>
The shape of the data I get from the service is:
{
"success": true,
"data": [
...
]
}
So after all of these steps, I get the error below:
Cannot find a differ supporting object '[object Object]' of type 'Player 1'. NgFor only supports binding to Iterables such as Arrays.
So what's going on here?
Observable.from(r.data)?Observabletothis.playersbecause of.map(r => Observable.from(r.data)).