【发布时间】:2018-11-05 11:53:26
【问题描述】:
我的组件中有这段代码:
ngOnInit() {
...
this.counterValue$ = interval(1000).pipe(
switchMap(() => this.perfService.getCounter(this.counterUrl)),
map(i => this.updateChart(i)),
);
this.counterValue$.subscribe(v => console.log(v));
}
我写这个是为了每 1 秒更新一次图表。问题是 perfService.getCounter() 需要超过 1 秒才能返回。这会导致以下 http 请求被取消:
如何解决这个问题?
【问题讨论】:
-
尝试使用mergeMap而不是switchMap