如何避免链接的角度订阅中的HTTP调用
我遇到过这样的情况:我调用 HTTP 服务来取回数据,然后根据该数据我需要立即进行另一个 HTTP 调用。通常我会将第一个输出通过管道传送到 switchMap 并完成。现在这是从路由订阅内部完成的,所以我不知道如何摆脱内部调用。
this.route.queryParamMap
.pipe(switchMap(params => someService.get(params))
.subscribe(x => {
// do other things with x
someService.getOtherThing(x.id).subscribe(...)
})
在 get(params)
调用完成之前,我无法调用 getOtherThing(x.id)
。如何避免在订阅中进行该服务调用?
I have a situation where I call an HTTP service to get data back, then based on that data I need to immediately make another HTTP call. Normally I'd pipe
the first output to a switchMap
and be done. That is now being done from inside a route subscription, so I'm not seeing how to get rid of the inner call.
this.route.queryParamMap
.pipe(switchMap(params => someService.get(params))
.subscribe(x => {
// do other things with x
someService.getOtherThing(x.id).subscribe(...)
})
I can't call getOtherThing(x.id)
until the get(params)
call completes. How do I avoid that service call from within the subscription?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
concatMap
将等待someService.get(params)
完成才能触发someService.getOtherThing(x.id)
concatMap
will wait forsomeService.get(params)
to be completed in order to triggersomeService.getOtherThing(x.id)