小编dla*_*lam的帖子

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

例如,我想每 10 秒更新一次列表。我使用了运算符“timer”,但 api 没有在 Chrome -> Network 选项卡上第二次显示。

我的流程:调度加载操作 - 我的 api - 方法 GET - 仅在“网络”选项卡中调用一次。但是,如果我创建了一个带有函数调度该操作的按钮,则每次我单击时,我的 api 都会在“网络”选项卡/Chrome 中被调用多次

我的环境:ngrx 7.4、rxjs 6.5.2、Angular 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]: …
Run Code Online (Sandbox Code Playgroud)

timer polling rxjs ngrx angular

0
推荐指数
1
解决办法
2510
查看次数

标签 统计

angular ×1

ngrx ×1

polling ×1

rxjs ×1

timer ×1