Rxjs的pipe怎么像Promise的then一样等待ajax结束才继续?

请问在Angular中,如果一个请求依赖于另外一个请求的结果,用Rxjs该怎么处理呢?

this.getOne().then(data => {  // 这里返回另外一个Promise
  return this.getTwo(data);
}).then(data => {
  console.log(data);  // 这里打印第二个Promise的值
  return this.getThree(data);
}).then(data => {
  console.log(data); // 这里打印第三个Promise的值})

上面是用Promise实现的效果,请问用Rxjs的pipe怎么达到类似的目的呢?


繁花不似锦
浏览 2262回答 1
1回答

慕姐8265434

mergeMap:from(this.getOne)     .pipe(         mergeMap(oneData => {            console.log(oneData)            return from(this.getTwo)         }),         mergeMap(twoData => {            console.log(twoData)            return from(this.getThree)         })     )     .subscribe(threeData => {        console.log(threeData)         ...     })
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript