我将依次从阵列向服务器发送数据。应在完成上一个请求后调用每个下一个调度。如何使用RxJS实现它?
P.S。它是角度4应用。
答案 0 :(得分:0)
如果您想链接Observables
,请使用.flatMap()
。它与.then()
Promise
相同
假设您的服务中有3个HTTP呼叫功能,称为firstRequest()
,secondRequest()
和thirdRequest()
。你可以像这样链接它们
myService.firstRequest()
.flatMap(result1 => {
//do something with result1 from firstRequest
return myService.secondRequest(result1)
.flatMap(result2 => {
//do something with result2 from secondRequest
return myService.thirdRequest(result2);
});
})
.subscribe(result3 => {
//finally do something with your result3 that is from thirdRequest
});