I am just beginning with Angular 6.
I folllowed the Hero Tutorial, and then replaced it with a real local API
now, instead of heroes, I have tournaments
but my API instead of returning an array of tournaments, it wraps it into a data object, so I can add metadata.
tournament.service.ts
getTournaments(): Observable<Tournament[]> {
this.messageService.add('TournamentService: fetched tournaments');
return this.http.get<Tournament[]>(this.tournamentsUrl)
.pipe(
tap(tournaments => this.log(`fetched tournaments`)),
catchError(this.handleError('getTournaments', []))
);
}
tournament.ts
export class Tournament {
id: number;
user: string;
date: string;
name: string;
numCompetitors: number;
}
tournaments I get from API:
"data": [
{
"id": 1,
"user": "[email protected]",
"date": "2018-06-13",
"name": "Fake Tournoi",
"numCompetitors": 86
},
{
"id": 2,
"user": "[email protected]",
"date": "2018-06-06",
"name": "Noel Kerluke",
"numCompetitors": 0
},
]
How should I do to always extract my array from data ?