RXJS-多个连续的HTTP请求 [英] RXJS - multiple consecutive http requests
本文介绍了RXJS-多个连续的HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
source<http>
.pipe(
switchMap(d => this.http.get(d))
.pipe(
switchMap(j => this.http.get(j))
)
)
.subscribe()
您好,我需要连续发出3个http请求,其中每个调用都包含下一个调用的数据..嵌套开关映射是这种情况下的最佳做法吗?
Hello, I need to make 3 http requests consecutively where each call contains data for the next call.. are nested switch maps the best practice for this case?
推荐答案
您无需嵌套它们.您可以简单地将它们链接起来:
You don't need to nest them. You can simply chain them:
source<http>
.pipe(
switchMap(d => this.http.get(d)),
switchMap(j => this.http.get(j))
)
.subscribe()
除此之外,使用多个 switchMap
是一种方法.
Apart from that, using multiple switchMap
is the way to go.
这篇关于RXJS-多个连续的HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文