【发布时间】:2018-04-17 09:26:08
【问题描述】:
我正在通过 Observable 进行 API 调用。如果此 API 调用超过 200 毫秒,我想显示一个加载屏幕(通过将 'true' 分配给我的 'loading' 变量),否则我不想显示任何内容,以避免在屏幕上闪烁。
有没有 RxJS 操作符可以做到这一点?
this.apiService.get(`/api/someEndpoint`)
// I hope for something like
.triggerIfAtLeastThisAmountOfTimeHasElapsed(200, () => {
this.loading = true;
})
.subscribe(response => {
// Process the response
this.loading = false;
});
【问题讨论】: