Making nested API calls in Angular

Viewed 1119

I need to make nested http calls in my angular app. First call returns the list of venues, then using each venue id i have to make multiple api calls to get details of each venue. Here is my code,

service.ts

GetResponse(){
     return this.http.get('someurl')//Returns list of venues
     .map(res => res.json())
     .flatMap(
     (result) =>{
       return 
         Observable.forkJoin(result.response.groups[0].items.map
                          ((data) => this.getDetailss(data))
     )});
}


getDetailss(venues) {
  return this.http.get('some url'/venues.id)// returns details of single venue
}

component.ts ,

this.service.GetResponse().subscribe(
(response)=> console.log(response),//Prints array of observables
(error)=>console.log(error)
);

I am receiving an array of observables in my component.How can i retrieve data from it in json form?

2 Answers
Related