【发布时间】:2020-02-29 16:52:08
【问题描述】:
例如,我想每 10 秒更新一次列表。我使用了运营商“计时器”,但 api 没有在 Chrome -> 网络选项卡上第二次显示。
我的流程:调度加载操作 - 我的 api - 方法 GET - 仅在网络选项卡中调用一次。 但是,如果我创建了一个具有功能调度该操作的按钮,则每次单击时,我的 api 都会在网络选项卡/Chrome 中被多次调用
我的环境:ngrx 7.4,rxjs 6.5.2,角度 7 所以我不知道服务器自动阻止重复调用 api 或者 angular 和 ngrx 是否正在使用缓存
//我的效果
load$: Observable<Action> = this.action$.pipe(
ofType<Load>(NotificationActionTypes.load),
switchMap(() => timer(0, 10000)),
switchMap((action) => {
return this.notiService.getNotifications().pipe(map((res: any) => {
return new LoadSuccess({
result: res,
});
}));
})
);```
[![enter image description here][1]][1]
See my image, 20/125 request, 125 continue increasing, 20/130, 20/145, but number 20 didn't increase
[1]: https://i.stack.imgur.com/tKgbE.png
【问题讨论】:
-
你想发送
NotificationActionTypes.load,还是应该每10秒调用一次api? -
@timdeschryver 因为我将通知列表保存在 ngrx 存储中并从中显示列表,在调度加载操作后,我将调度 LoadSuccess 以保存数据。我的意思是我想每 10 秒调用一次 api 来获取最新列表。 blog.thoughtram.io/angular/2018/03/05/… 好像是这样的,但它没有ngrx,所以我应用了它但没有用
标签: angular timer rxjs ngrx polling