RxJs Observables嵌套订阅吗? [英] RxJs Observables nested subscriptions?
本文介绍了RxJs Observables嵌套订阅吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
简化以下代码示例的方法是什么? 我找不到合适的运算符..有人可以举一个简短的例子吗?
Whats the way to simplify something like the following code example? I can't find the right operator.. could anyone give a short example?
this.returnsObservable1(...)
.subscribe(
success => {
this.returnsObservable2(...)
.subscribe(
success => {
this.returnsObservable3(...)
.subscribe(
success => {
...
},
推荐答案
如注释中所述,您正在寻找flatMap
运算符.
As mentioned in comments, you are looking for the flatMap
operator.
您可以在以前的答案中找到更多详细信息:
You can find more details in previous answers :
- How to do the chain sequence in rxjs
- Why do we need to use flatMap?
您的示例为:
this.returnsObservable1(...)
.flatMap(success => this.returnsObservable2(...))
.flatMap(success => this.returnsObservable3(...))
.subscribe(success => {(...)});
这篇关于RxJs Observables嵌套订阅吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文