I have a problem with async pipe and observer combination. I have been trying to create a team.service with 'players'and app.component, that will get that data. I am getting the following error:
InvalidPipeArgument: '[object Object],[object Object],[object Object]' for pipe 'AsyncPipe'
Morethere, When I erase async pipe, it works. Do someone know how to fix? My code
team.service:
export class TeamService {
fillPlayers(): any {
return [
{ 'name': 'Buzz', 'surname': 'Astral' },
{ 'name': 'Mad', 'surname': 'Max' },
{ 'name': 'Eazy', 'surname': 'E' }
];
}
constructor() {}
getPlayersWithObservable(): Observable<TeamInterface[]> {
return this.fillPlayers();
}
}
app.component.ts
export class AppComponent {
observableTeam: Observable<TeamInterface[]>;
constructor(private _teamService: TeamService) {}
ngOnInit() {
this.observableTeam = this._teamService.getPlayersWithObservable();
}
}
app.component.html
<ul>
<li *ngFor="let player of observableTeam | async">
{{ player.name }}
</li>
</ul>