发生有效果的无限循环-Angular ngrx8

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

有几个与此相关的问题。.但是我经历了所有问题,但问题没有解决。基本上我是一个初学者,所以我无法跟踪问题。

这是我的效果:

readMsg$ = createEffect(() => this.actions$.pipe(
  ofType(readMsg),
  map(action => action.payload),
  switchMap((reqPayload: MsgReadRequest) => {
      return this.httpService.post('api/msgread', reqPayload)
      .pipe(
        map((resp: MsgReadResponse) => resp.message === 'ok' ?
        readMsgSucess({payload: resp}) :
        readMsgFailure({payload: resp}),
        catchError((error: HttpErrorResponse) => of(error.message))
      )
    );
    })
));

这些是我的动作:

export const readMsg  = createAction('[Read] Msg in xl', props<{payload: NewsReadRequest}>());
export const readMsgSucess  = createAction('[Read] Msg in xl', props<{payload: NewsReadResponse}>());
export const readMsgFailure  = createAction('[Read] Msg in xl', props<{payload: NewsResponse}>());
export const htttpError  = createAction('[Read] Msg in xl error', props<{payload: HttpErrorResponse}>());
angular ngrx ngrx-effects
2个回答
2
投票

一个简单的错误。在“动作”中,我不应该提及相同的语句。.我只是更改了如下所示的动作,现在一切正常。.

export const readMsg  = createAction('[Read] Msg in xl', props<{payload: NewsReadRequest}>());
export const readMsgSucess  = createAction('[Read] Msg in xl success', props<{payload: NewsReadResponse}>());
export const readMsgFailure  = createAction('[Read] Msg in xl failure', props<{payload: NewsResponse}>());
export const htttpError  = createAction('[Read] Msg in xl error', props<{payload: HttpErrorResponse}>());

0
投票

也许这可以帮助您

readMsg$ = createEffect(() => this.actions$.pipe(
  ofType(readMsg),
  map(action => action.payload),
  switchMap((reqPayload: MsgReadRequest) => 
    this.httpService.post('api/msgread', reqPayload)
      .pipe(
        map((resp: MsgReadResponse) => resp.message === 'ok' ?
        readMsgSucess({payload: resp}) :
        readMsgFailure({payload: resp}),
        catchError((error: HttpErrorResponse) => of(error.message))
      )
    ))
));
© www.soinside.com 2019 - 2024. All rights reserved.