是否可以访问 RxJs 组件中以前的管道变量,其中 forkJoin()
或 combineLatest()
不能使用,在我的例子中是由于值累积,而不嵌套管道?
或者在下面的场景中带有 switchMap()
的嵌套管道还可以吗?
// this.incrementNavigation$ emits always 1
// this.decrementNavigation$ emits always -1
this.searchSuggestions$.pipe(
// Can't use combineLatest() due to accumulation happening in scan()
switchMap(search => {
return merge(this.incrementNavigation$,this.decrementNavigation$).pipe( // nesting begins...
startWith(0),scan((acc: number,cur: number) => {
if (acc+cur < 0) return search.length-1 // Need access to search variable
if (acc+cur > search.length-1) return 0
return acc+cur
}),)
})
).subscribe(pos => {
this.searchNavigationPosition = pos
})