'How to chain subscriptions and return a single observable

i m trying to chain 3 subscriptions in a service and return an observable so all the components can subscribe single observable. When i console.log "_campaigns" its always empty. I believe some sync. problem there. the I m new to Rx.js, any ideas how could i achieve this ?



Solution 1:[1]

If those are single shot streams (like http requests) then forkJoin and you are good to go

forkJoin([
 this.cmsListSuccessSub$,this.userListSuccessSub$,this.publicListSuccessSub$
]).pipe(map(arr=>([...arr[0],...arr[1],...arr[2])).subscribe((allItems)=>this._cmsCampaigns = items)

If those are continous, use mergeAll

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1