[英]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.