I am writing a simple Angular application that calls to an external API for data. One of these API calls returns data in such a way:
{
"data": {
"items": [
{
// An Appointment object is here
},
{
...
}
]
}
}
I have an AppointmentService which I use to call the API using the Angular HTTP library:
getBookedAppointments(userID : number) : Observable<Appointment[]> {
return this.http.get<Appointment[]>('/api/url/goes/here')
.pipe(retry(2), catchError(this.handleError));
}
And finally, I am trying to get these Appointment objects into an Array:
this.AppointmentService.getBookedAppointments(id).subscribe((appts : Appointment[]) => {
// appts contains {"data" : {"data": {"items" : [...]}}}
})
The issue being the fact that the API returns the array nested within data.items. How can I properly map the response so that the array is not nested?