'combining 3 subjects with combineLatest and return an observable

I have 3 subjects. Would like to subscribe them, fill a global array of items with values from those Subjects and return this array as observable so all the components can subscribe. When i tried it with combineLatest couldnt get any results. Any ideas how to achieve this ?

 public loaditems() {
   return combineLatest(
      of(this.paginatorSuccessSub$).pipe(startWith(null)),
      of(this.sortSuccessSub$).pipe(startWith(null)),
      of(this.filtersSuccessSub$).pipe(startWith(null)),
    ).pipe(
      map(value => {
        const paginator = this.appendPaginators(value[0]); // method fills the global array of items
        const sort = this.appendSortedItems(value[0]);// method fills the global array of items
        const filters = this.appendFilters(value[0]);// method fills the global array of items
        console.log(paginator, sort, filters)
        return of(this._items)
      }))
  }


Solution 1:[1]

combineLatest Takes Observable as input, Subject inherit from Observable so you just have to pass in subject without wrapping it with of()

  return combineLatest(
      this.paginatorSuccessSub$.pipe(startWith(null)),
      this.sortSuccessSub$.pipe(startWith(null)),
      this.filtersSuccessSub$.pipe(startWith(null)),
    )

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 Fan Cheung