[英]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.