I have doubts about how to consume JSON in Angular, since I can not use the JSON data well in my model.
JSON example: link
My model is as follows
export class Artist {
idArtist: string;
strArtist: string;
strStyle: string;
strWebsite: string;
strBiographyES: string;
strArtistLogo: string;
strArtistBanner: string;
}
My Observable:
getArtist(): void {
this.musicService.getArtist()
.subscribe(artists => this.artist = artists );
}
My method for API consumption:
getArtist(): Observable<Artist[]> {
const URL = 'http://www.theaudiodb.com/api/v1/json/1/search.php?s=coldplay';
return this.httpClient.get<Artist[]>(URL).pipe(
tap( _ => console.log('artist found')),
catchError( this.handleError('getArtist', []))
);
}
If I make a print of my Artist type object in TypeScript, I get EXACTLY the same as in the previously exemplified JSON example. Why should not he machete? How can I solve it?
The model can be modified if necessary, I have no restrictions of any kind.