RxJS Observables 嵌套订阅? [英] RxJS Observables nested subscriptions?

查看:26
本文介绍了RxJS Observables 嵌套订阅?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简化以下代码示例的方法是什么?我找不到合适的操作员..谁能举一个简短的例子?

What's 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 :

你的例子应该是:

this.returnsObservable1(...)
  .flatMap(success => this.returnsObservable2(...))
  .flatMap(success => this.returnsObservable3(...))
  .subscribe(success => {(...)}); 

这篇关于RxJS Observables 嵌套订阅?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆