RxJs Observables nested subscriptions?

前端 未结 3 768
清歌不尽
清歌不尽 2020-11-29 06:22

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.returnsObserv         


        
3条回答
  •  Happy的楠姐
    2020-11-29 07:11

    Previously answered for RxJS 5, I ended up on this page whilst using 6.

    In the case you're on 6 as well (and I think you should be by now) you can use flatmap as an operator within pipe.

    Modified the example code of @user3743222:

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

提交回复
热议问题