RXJS - 多个连续的 http 请求

s1e*_*per 2 rxjs angular rxjs6

source<http>
  .pipe(
    switchMap(d => this.http.get(d))
      .pipe(
        switchMap(j => this.http.get(j))
      )
  )
  .subscribe()
Run Code Online (Sandbox Code Playgroud)

您好,我需要连续发出 3 个 http 请求,其中每个调用都包含下一次调用的数据。嵌套切换映射是这种情况下的最佳实践吗?

pas*_*etz 5

你不需要嵌套它们。您可以简单地将它们链接起来:

source<http>
  .pipe(
    switchMap(d => this.http.get(d)),
    switchMap(j => this.http.get(j))
  )
  .subscribe()
Run Code Online (Sandbox Code Playgroud)

除此之外,使用多个switchMap是要走的路。