简体   繁体   English

等待http请求完成,然后在角度6的另一个http请求中使用结果

[英]wait http request to finish, then use the result in another http request in angular 6

i have to make 2 http requests, the second one depends on the first one's result. 我必须发出2个http请求,第二个请求取决于第一个请求的结果。 How to make it possible ? 如何使其成为可能? I tried subscribe and map, but not working. 我尝试订阅和地图,但无法正常工作。 Thank you for yor time 谢谢你的时间

hard to show you without your own code but it would look something like this: 没有您自己的代码很难向您展示,但是看起来像这样:

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

switchmap takes the value from 1 observable response and switches into another observable. switchmap从1个可观察的响应中获取值,然后切换到另一个可观察的响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM