EDIT: no need to answer, the problem was elsewhere. I apologize :(
I need getHeroes() to return an array of 'Hero'. It was working with the tutorial's in-memory data, but fails when I use my django rest API.
hero.ts
export class Hero {
id: number;
name: string;
}
hero.service.ts
getHeroes (): Observable<Hero[]> {
return this.http.get<Hero[]>(this.heroesUrl).pipe(
map(response => response['heroes']),
tap(_ => this.log('fetched heroes')),
catchError(this.handleError<Hero[]>('getHeroes', []))
);
}
JSON response from API
{
"heroes": [
{
"id": 1,
"name": "hero1"
},
{
"id": 2,
"name": "hero2"
}
]
}