簡體   English   中英

將 3 個主題與 combineLatest 結合起來並返回一個可觀察的

[英]combining 3 subjects with combineLatest and return an observable

我有 3 個科目。 想要訂閱它們,用這些主題的值填充一個全局項目數組,並將該數組作為可觀察的返回,以便所有組件都可以訂閱。 當我用 combineLatest 嘗試時,無法得到任何結果。 任何想法如何實現這一目標?

 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)
      }))
  }

combineLatest Observable作為輸入, Subject繼承自Observable所以你只需要傳入 subject 而無需使用of()包裝它

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM