【发布时间】:2018-11-08 18:19:12
【问题描述】:
我在尝试合并 observbles 时收到错误 You provided 'undefined' where a stream was expected.。
我在这里创建我的刷新观察:
refresh$: Observable<Funnel[]>;
那我有一个计时器...
TimerObservable.create(0, (this.storageService.refRate * 1000))
.takeWhile(() => this.interval)
.subscribe(() => {
this.refresh$ = this.funnelService.getStoryFunnels({}).map(response => [...response]);
});
然后当我尝试合并 observable 时,就会产生错误:
this.funnels$ = this.funnelService.getStoryFunnels({}).pipe(
merge(this.refresh$, funnelCreation$.pipe(
filter(funnel => !!funnel),
map(funnel => [funnel])
)
)
);
根据舒适的回答更新:
this.refresh$ = TimerObservable.create(0, (this.storageService.refRate * 500))
.takeWhile(() => this.interval)
.switchMap(() => this.funnelService.getStoryFunnels({}).map(response => [...response]));
然后:
this.funnels$ = this.funnelService.getStoryFunnels({}).pipe(
merge(this.refresh$, funnelCreation$.pipe(
filter(funnel => !!funnel),
map(funnel => [funnel])
)
)
);
【问题讨论】:
-
刚刚意识到您
refresh$和funnel$都依赖于this.funnelService.getStorryFunnels()。你到底想达到什么目的? -
@CozyAzure 我们正尝试每两分钟更新一次显示。所以 this.funnels 是传递给模板的异步,而 refresh 只是为了更新它。
-
那么你根本不需要合并。只需将
this.refresh$传递给您的模板,它应该可以按预期工作。