0

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]]

1 Answer 1

2

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));
Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what I needed. Big thanks! You saved my day! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.