For example, there is /api/item/1 , which returns {id: 1, data: "data1"} and /api/item/2 , which returns {id: 2, data: "data2"} , and so on. I want to array all the objects so that I get [{id: 1, data: "data1"}, {id: 2, data: "data2"}] . I tried to do by example:

 Observable.from(ids) .mergeMap(res => this.getItemById(res)) //метод возвращающий Observable .concatAll() 

Did not work, tell me how to do it?

  • and ids what is yours? - n3r0bi0m4n
  • @ n3r0bi0m4n array of id items, for my example it will be [1,2, ...], according to which the query occurs. The this.getItemById (id) method executes this request and returns Observable <Item>. I want to convert these sequential requests to different URLs so that I immediately get an array of results. Is it even possible? - Oblfakir
  • Is n't that right? - n3r0bi0m4n
  • @ n3r0bi0m4n In this embodiment, you must manually list Observable. I seem to have found a working version, I will add as an answer. - Oblfakir

1 answer 1

This option worked:

 Observable.from(ids) .map((id: number) => {return this.getItemById(id)}) .mergeAll().toArray(); 

Perhaps you can solve this more easily.