【问题标题】:wait http request to finish, then use the result in another http request in angular 6等待http请求完成,然后在角度6中的另一个http请求中使用结果
【发布时间】:2019-07-14 18:23:54
【问题描述】:

我必须发出 2 个 http 请求,第二个取决于第一个的结果。如何使它成为可能?我尝试订阅和映射,但没有工作。谢谢你的时间

【问题讨论】:

  • 发布您的代码。

标签: angular angular6 httprequest


【解决方案1】:

如果没有您自己的代码,很难向您展示,但它看起来像这样:

this.request1().pipe(
  switchMap(result1 => this.request2(result1.neededProp))
).subscribe(result2 => console.log(result2))

switchmap 从 1 个 observable 响应中获取值并切换到另一个 observable。

【讨论】:

    猜你喜欢
    • 2017-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-19
    • 1970-01-01
    • 2018-07-19
    相关资源
    最近更新 更多