【发布时间】:2020-03-26 22:59:27
【问题描述】:
我有一个在另一个订阅中订阅的案例,我们知道这很糟糕。问题是我不知道如何在这里解决它:
this.backendService.doSomething().subscribe(
() => { },
err => {
this.someService.showOkMessage('title', 'you got an error')
.subscribe(); // The bad guy
},
() => {
// should not be called if there is an error
this.someService.showOkMessage('title', 'everything is fine')
.subscribe(); // Another bad guy
}
}
我尝试过这样的事情:
this.backendService.doSomething().pipe(
catchError(errMsg => {
return someService.showOkMessage('title', 'you got an error').map(() => true));
)},
switchMap(isError =>
if(!isError) return someService.showOkMessage('title', 'everything is fine');
)
).subscribe();
这可行,但感觉不对,我不想转换/更改流,它应该结束。
【问题讨论】: