[英]Infinite loop happening with effects - Angular ngrx8
有几个与此相关的问题。但我经历了所有但我的问题没有解决。 基本上我是初学者,所以我无法追踪问题。
这是我的效果:
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}>());
一个简单的错误.. 在 Actions 中,我不应该提及相同的语句..我只是更改了如下所示的操作,现在一切正常..
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}>());
也许这可以帮助你
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))
)
))
));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.