管道操作员时如何返回可观察到的"forkJoin" [英] How to return a `forkJoin` observable when piping the operators
问题描述
在我使用此解析器之前,它工作得很好:
Before I had this resolver that just worked fine:
resolve() {
return forkJoin(
this.getData1(),
this.getData2(),
this.getData3()
);
}
现在我必须做一些实际上是行不通的事情:
Now I have to do something like that which is actually does not work:
resolve() {
return this.actions$
.pipe(
ofActionSuccessful(SomeSctonSuccess),
forkJoin(
this.getData1(),
this.getData2(),
this.getData3()
)
);
}
当我遇到此错误时:
'Observable< [任何,任何,任何,任何]>类型的参数不可分配 到"OperatorFunction"类型的参数.类型 'Observable< [[任何,任何,任何,任何]>'不提供签名的匹配项 (来源:可观察):可观察".
Argument of type 'Observable<[any, any, any, any]>' is not assignable to parameter of type 'OperatorFunction'. Type 'Observable<[any, any, any, any]>' provides no match for the signature '(source: Observable): Observable'.
任何想法如何解决?
现在,我只在ofActionSuccessful(SomeSctonSuccess)
发生后才注意返回我的forkJoin
https ://ngxs.gitbook.io/ngxs/advanced/action-handlers
Now I heed to return my forkJoin
only after ofActionSuccessful(SomeSctonSuccess)
is taking place https://ngxs.gitbook.io/ngxs/advanced/action-handlers
推荐答案
使用exhaustMap
运算符.它映射到内部可观察的对象,忽略其他值,直到该可观察的对象完成
Use exhaustMap
operator. It maps to inner observable, ignore other values until that observable completes
import { forkJoin } from 'rxjs';
import { exhaustMap } from 'rxjs/operators';
resolve() {
return this.actions$
.pipe(
ofActionSuccessful(SomeSctonSuccess),
exhaustMap(() => {
return forkJoin(
this.getData1(),
this.getData2(),
this.getData3()
)
})
);
}
这篇关于管道操作员时如何返回可观察到的"forkJoin"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!