I am facing an issue with the for each loop not waiting for the map function to finish, resulting in undefined ids. How can I ensure that all the ids are properly mapped?
getIndexes(){
this.http.get<{data: {id: number, caption:string}[], paging: any, next: string}>(this.baseUrl +'me/media/?access_token=' + this.users + '&fields=id,caption&limit=9',
{responseType:"json"}).subscribe(response =>
{
const data = response.data.map(async l => {
l.id
})
data.forEach(
id => {
this.http.get<{ media_url: string; id: string; }>(this.baseUrl + id + '/?access_token=' + this.users + '&fields=media_url').subscribe(res => {
console.log(this.list);
this.list.push(res.media_url);
console.log(this.list);
this.gallery.next(this.list);
});
}
);
}
)
}