-1

My question can be obvious but I’m new at RxJs and get lost in the descriptions of dozen of operators.

I have an angular 8 project. I have 5 observables. I need to put all data from them into one stream. As result I expect sorted list or array , sort criteria- by date. And also I need to recognize in my html-template which data type every object is. I have read about mergeMap, forkJoin . But can’t choose right for my task. Please help!

Zelena
  • 63
  • 8
  • Does your observables depend on each other? Also you could share some code about you context and sample data. – robert Aug 09 '19 at 20:27
  • 5
    The RxJS [operator decision tree](https://rxjs-dev.firebaseapp.com/operator-decision-tree) can help you to choose the appropriate operator. – ConnorsFan Aug 09 '19 at 20:36
  • You can make use of `forkJoin()`. I have some examples over [here](https://stackoverflow.com/questions/55686084/making-sure-observables-in-for-loop-are-all-finished-before-executing-other-code/55686179#55686179) and [here](https://stackoverflow.com/questions/54457374/subscribe-to-multiple-async-http-calls/54457487#54457487) – wentjun Aug 09 '19 at 21:04

1 Answers1

0

If you're OK with waiting until all Observables complete, you can use forkJoin. This returns the last emit of each Observable passed into it once all have completed. You can pass a dictionary of the Observables into forkJoin() to be able to identify which output in your result belongs to which Observable (see the first example at the provided link.)