ngrx调度的操作未达到效果



我是@ngrx的新手。我在business-unit.actions.ts中创建了一个@ngrx操作,并从组件中分派了这个操作。但由于某种未知的原因,该行动没有达到相关效果。我浏览stackoverflow和其他@ngrx教程。我已经向Redux devtools检查了loadSearchBusinessUnits操作的完美调度,但它没有达到@ngrx/effects。任何形式的帮助都将不胜感激。提前谢谢。

这是我的business-unit.actions.ts文件;

enum BusinessUnitActionsTypes {
LoadSearch = '[Business-units] Load Search',
LoadSearchSuccess = '[Business-units] Load Search Success',
LoadSearchFailure = '[Business-units] Load Search Failure',
}

export const loadSearchBusinessUnits = createAction(
BusinessUnitActionsTypes.LoadSearch,
props<{ search: string }>()
);
export const loadSearchBusinessUnitsSuccess = createAction(
BusinessUnitActionsTypes.LoadSearchSuccess,
props<{ businessUnits: BusinessUnit[] }>()
);
export const loadSearchBusinessUnitsFailure = createAction(
BusinessUnitActionsTypes.LoadSearchFailure,
props<{ errorMsg: string }>()
);

这是我的业务部门效果代码

loadSearchBusinessUnit$ = createEffect(() => this.actions$.pipe(
ofType(BusinessUnitActions.loadSearchBusinessUnits),
switchMap(({ search }) => this.businessUnitService.loadBusinessUnitsSearch(search).pipe(
map((businessUnits: BusinessUnit[]) => {
return BusinessUnitActions.loadSearchBusinessUnitsSuccess({ businessUnits });
}),
catchError(response => of(BusinessUnitActions.loadSearchBusinessUnitsFailure({
errorMsg: response.error
})))
))
));

在type内部传递操作类型,而不是操作对象。

loadSearchBusinessUnit$ = createEffect(() => this.actions$.pipe(
ofType(BusinessUnitActions.LoadSearch),
switchMap(({ search }) => this.businessUnitService.loadBusinessUnitsSearch(search).pipe(
map((businessUnits: BusinessUnit[]) => {
return BusinessUnitActions.loadSearchBusinessUnitsSuccess({ businessUnits });
}),
catchError(response => of(BusinessUnitActions.loadSearchBusinessUnitsFailure({
errorMsg: response.error
})))
))
));

相关内容

  • 没有找到相关文章

最新更新