每x秒调用api不适用于Ngrx + Angular

问题描述 投票:0回答:1

例如,我想每10秒更新一次列表。我使用了运算符'timer',但是api在Chrome->“网络”标签上没有第二次显示。

[我的过程:调度加载操作-我的API-GET方法-在“网络”标签中仅被调用一次。但是,如果我创建了一个带有分派该动作的功能的按钮,则每次点击[

我的环境: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,
        });
      }));
    })
  );```
angular timer rxjs ngrx polling
1个回答
0
投票

尝试将第二个switchMap更改为mergeMap

this.action$.pipe(
    ofType<Load>(NotificationActionTypes.load),
    switchMap(() => timer(0, 10000)),
    mergeMap((action) => {.....
© www.soinside.com 2019 - 2024. All rights reserved.