Encountering the error message "data.map is not a function" while trying to map data from a REST API request returning JSON data. It appears that the issue may stem from the data structure, as it seems like the returned data should be accessed with data.data instead of data. Any suggestions on how to properly handle this mapping would be greatly appreciated.
Take a look at the JSON Data Structure.
Below is the service code snippet:
getAlladvisors$ = this.http.get<IAdvisor[]>("http://localhost:8055/items/advisor")
.pipe(
map((data: IAdvisor[]) =>
data.map(
a =>
({
name: a.name,
id: a.id,
page: a.page,
multilang: a.multilang
})
)
),
AdvisorsandQuestions$ = this.http.get<IAdvisorsAndQuestions[]>("http://localhost:8055/items/question")
.pipe(
tap(data => console.log("Questions IDs", data))
);
getAdvisorsWithId$ = combineLatest([
this.getAlladvisors$,
this.AdvisorsandQuestions$
]).pipe(
map(([product, categories]) =>
product.map(product => ({
...product,
questionId: categories.find(c => product.id === c.id).questions_Id,
}) as IAdvisor)
),
);
Here is the Interface definition:
export interface IAdvisor {
id: number,
name: string,
page: string,
multilang: boolean
}