Issue
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.
Solution
It looks like the return type is an array. So you probably need to access the first element (or similar).
this.hero = fetchedHero[0];
Answered By - batman567
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.