如何在 NgRx 中获取动作参数?
How to get action parameter in effect NgRx?
我发送带参数的操作并替换 (block.id)
?
上的 (9)
this.store.dispatch(RegistryActions.LoadRegistryLayersAction(this.block));
如何让这个参数生效?
loadRegistriesLayers$: Observable<Action> = createEffect(() =>
this.actions$.pipe(
ofType(RegistryActions.LoadRegistryLayersAction),
switchMap(() =>
from(this.registryService.getRegistryPolygonsPolygons(9)).pipe(
map((layers: { [key: string]: RegistryLayerItemGeneric[] }) => {
return RegistryActions.SuccessLoadRegistryLayersAction({
payload: layers,
});
}),
catchError((error: Error) => {
return of(RegistryActions.ErrorRegistryLayersAction(error));
})
)
)
)
);
您应该可以在 switchMap 中访问它,如下所示:
switchMap((action: {..your type}) =>
from...
我发送带参数的操作并替换 (block.id)
?
(9)
this.store.dispatch(RegistryActions.LoadRegistryLayersAction(this.block));
如何让这个参数生效?
loadRegistriesLayers$: Observable<Action> = createEffect(() =>
this.actions$.pipe(
ofType(RegistryActions.LoadRegistryLayersAction),
switchMap(() =>
from(this.registryService.getRegistryPolygonsPolygons(9)).pipe(
map((layers: { [key: string]: RegistryLayerItemGeneric[] }) => {
return RegistryActions.SuccessLoadRegistryLayersAction({
payload: layers,
});
}),
catchError((error: Error) => {
return of(RegistryActions.ErrorRegistryLayersAction(error));
})
)
)
)
);
您应该可以在 switchMap 中访问它,如下所示:
switchMap((action: {..your type}) =>
from...