给一个像这样的switchMap
const sw = switchMap(() => {
if (/*some condition*/) { return this.getDetails().pipe(...) }
return this.getOtherDetails().pipe(....);
});理想情况下,我想使用它,例如,如下所示
from(sw).subscribe(....)但这行不通:)
那我该怎么做呢。我能想到一个解决办法
of(true).pipe(sw).subscribe(...)但这感觉不对,是吗?我可以想象RxJS对于这类问题有一个更好的解决方案。有什么建议吗?
发布于 2022-09-06 00:58:37
@martin的评论是对的。
它感觉不对的原因是因为你没有从一个事件或者你等待的任何事情开始。你最好有一种方法
getAppropriateDetails$() {
if (/*some condition*/) {
return this.getDetails$();
}
this.getOtherDetails$();
});然后你就可以像
this.getAppropriateDetails$().pipe(
...
).subscribe (
...
)发布于 2022-09-06 06:45:48
你可以直接用张力操作符。
([some condition] ? this.getDetails().pipe(...) : this.getOtherDetails().pipe(...)).subscribe(...);https://stackoverflow.com/questions/73614764
复制相似问题