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

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

我的过程:分派Load操作-我的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]: https://i.stack.imgur.com/tKgbE.png
java21710397 回答:每x秒调用api不适用于Ngrx + Angular

如果您希望每隔x秒重新加载一次,则不必调度操作,只需使用timer流:

@Effect()
ping = interval(10000).pipe(
  switchMap((action) => {
    return this.notiService.getNotifications().pipe(map((res: any) => {
      return new LoadSuccess({
        result: res,});
    }));
}));

更多信息,Start using ngrx/effects for this

本文链接:https://www.f2er.com/3167235.html

大家都在问