I need to call an api which will return an array of objects. Then I need to loop through all the objects and using an id from each object i need to call another api. Then I am planning to save the data in an array and subscribe, so that I have access to the custom array that contains data from the both api calls. However it is not working for me.
I need combined data from both api calls, however in the resulting array that I am creating, the data from the second api is appearing as observable and when I am trying to use them I am getting undefined error. Any help will highly appreciated.
this.apiService.getIntakeEvents(90430)
.pipe(mergeMap((res: any)=>{
const allData =[];
for(const item of res) {
let courseInfo = this.apiService.getSpecificCourse(item.courseId)
allData.push({...item, courseInfo})
}
console.log(allData)
return allData;
}))
.subscribe(res=> console.log(res))