【发布时间】:2019-07-14 18:23:54
【问题描述】:
我必须发出 2 个 http 请求,第二个取决于第一个的结果。如何使它成为可能?我尝试订阅和映射,但没有工作。谢谢你的时间
【问题讨论】:
-
发布您的代码。
标签: angular angular6 httprequest
我必须发出 2 个 http 请求,第二个取决于第一个的结果。如何使它成为可能?我尝试订阅和映射,但没有工作。谢谢你的时间
【问题讨论】:
标签: angular angular6 httprequest
如果没有您自己的代码,很难向您展示,但它看起来像这样:
this.request1().pipe(
switchMap(result1 => this.request2(result1.neededProp))
).subscribe(result2 => console.log(result2))
switchmap 从 1 个 observable 响应中获取值并切换到另一个 observable。
【讨论】: