如何取消在 RXJS Effects 中发出的 angular http 请求

How cancel angular http request made in RXJS Effects

我想在 angular 8.

中取消 RXJS 效果中的 http 请求
@Effect() getReport$ = this.action$.pipe(
ofType(ActionTypes.GET_WIDGET),   
map(toPayload),
mergeMap(payload => {
  return this.dashboardService.getReport(payload).pipe(
    map(this.extractData),
    switchMap(result => {
      return observableOf(<ReceivedWidgetAction>{
        type: ActionTypes.RECEIVED_WIDGET,
        payload: result
      });
    }),
    catchError((err: Response | any) => {
      return this.handleReportError(err);
    }));

}));

请告诉我如何使用 angular 8 做同样的事情。另请注意,我将无法使用切换地图,因为多个小部件 angular 组件将调用此操作不同的有效负载。

我们可以通过使用 takeUnitil 运算符来取消正在进行的请求,并在需要取消请求时创建新的操作并使用存储分派相同的操作。

 @Effect() getReport$ = this.action$.pipe(
ofType(ActionTypes.GET_WIDGET),   
map(toPayload),
mergeMap(payload => {
  return this.dashboardService.getReport(payload).pipe(
    map(this.extractData),
    switchMap(result => {
      return observableOf(<ReceivedWidgetAction>{
        type: ActionTypes.RECEIVED_WIDGET,
        payload: result
      });
    }),
    takeUntil(this.action$.pipe(ofType(DashboardActionTypes.CANCEL_REQUEST))),
    catchError((err: Response | any) => {
      return this.handleReportError(err);
    }));

}));