【发布时间】:2017-12-28 00:25:15
【问题描述】:
当我需要在 Observable 上使用 switchMap 两次(独立查询)时,最佳做法是什么。我需要从 activeRoute.ParamMap... 返回的 Id 用于两个独立的查询。只有一个查询,我会执行以下操作:
this.route.paramMap
.switchMap((params: ParamMap) =>
this.service.getSomeInformation(params.get('id')));
现在我需要从路由返回的 ID 用于另一个查询
this.route.paramMap
.switchMap((params: ParamMap) =>
this.AnotherService.getSomeMoreInformation(params.get('id')));
所以我需要从 paramMap 中提取的 Id 作为服务和 anotherService 的输入。
最佳做法是什么?把它们锁起来?来自 Service 和 AnotherService 的 Observables 的时间无关紧要。
由于这是我在这里的第一个问题,请让我知道在下一个问题中我可以做得更好。
谢谢, 史蒂芬
【问题讨论】:
-
将id值存储在一个observable中,然后用那个+switchMap来使用服务?
标签: angular rxjs angular2-observables angular-router switchmap