1

I'm facing an issue with observable.from(). I have an array of ID's and for each ID I need to perform an async operation and return a value.

I want after all of the ID's complete their inner async operation to get the value of all of them together (Not one by one).

This is my code:

Observable.from(IDs)
        .mergeMap(ID=> this.getDataByID(ID)
          .map(data => Observable.of(Object.assign({}, data, dataUpdate[ID]))))
        .subscribe(newData=> {
          ...
        })

The dataUpdate is an object from outside of this scope witch hold data I want to append to the object fetched by getDataByID().

In this case the subscriber been called for every event ID and newData contains the data for only one ID.

Can I make the newData to hold an object/array of all of the data instead of one by one?

Thanks.

Gili Yaniv
  • 3,073
  • 2
  • 19
  • 34

1 Answers1

0

in this case you will need to use another RxJS operator , such as forkjoin http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#static-method-forkJoin

You can take a look at this as well Multiple ajax call in angular2

Vi Elite
  • 136
  • 2
  • 6