[英]Return result of an observable with combineLatest and Rxjs
[英]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.