How to execute another observable based on array from result returned from another one
I have a quite simple situation but i got stuck. I have function customGalleriesHttpService.list()
which returns observable with array of items. Lets assume:
[
{id:1,
... other stuff
},
{id:2,
... other stuff
}
]
Now I want to take each element from this array and make an extra http request customGalleriesHttpService.images(data.id)
which returns observable with array of images for particular elemend based on his id. What i achived so far.
this.customGalleriesHttpService.list().pipe(
concatMap((data) => data),
mergeMap((data) => this.customGalleriesHttpService.images(data.id)),
).subscribe((data) => console.log(data));
it is working but there is on more thing. It gives me output like this:
Array[6], Array[6]
what i want to achive is to group this and return [Array[6], Array[6]]
Add a toArray()
operator before subscribe should work
this.customGalleriesHttpService.list().pipe(
concatMap((data) => data),
mergeMap((data) => this.customGalleriesHttpService.images(data.id)),
toArray(),
).subscribe((data) => console.log(data));