I have a problem with mapping fetched JSON from the API to an existing object. TypeScript code:
Hero Interface:
export interface Hero {
id: number;
name: string;
}
Console log:
this.hero
is always empty (undefined). How to solve this
PS. I'm new in Angular and typescript.
It looks like the return type is an array. So you probably need to access the first element (or similar).
this.hero = fetchedHero[0];