The problem that you probably ran into is that you have not ironed enough.
flatMap or mergeMap will smooth out Observables , Promises , Arrays , even generators (don't quote me on the latter), just about what you want to throw at it.
So, when you do .flatMap(items => items.map(item => this.fetchItem(item)) , you really just do Observable<Array<Item>> => Observable<Observable<Item>>
When you just make a map , you do Observable<Array<Item>> => Observable<Array<Observable<Item>>> .
What you need to do is first smooth the array and then smooth each request:
class ItemsService { fetchItems() { return this.http.get(url) .map(res => res.json())
Now the above works if you do not mind that each answer of each element is individual. If you need to get all the items, you should use forkJoin for all the internal values, but you still need a flatMap in to smooth out the resulting internal value:
fetchItems(): Observable<Response[]> { return this.http.get(url) .map(res => res.json()) .flatMap(items => { const requests = items.map(item => this.fetchItem(item)); return Rx.Observable.forkJoin(requests); }); }
source share