Issue
I'm playing around with angular and ngrx/store 17.
I set up some actions, defined the relatives reducers and dispatched the action, but this error is showing up:
TypeError: can't access property "type", creator is undefined
It happens inside function on()
when it tries to extract the action's type and the cause seems to be the action being undefined.
I did this things so many time I can't count, but something like this never happened to me.
This is the definition of my action
export const setTitle = createAction(`Set title`, props<{ title: string }>());
the reducer
export const sharedFeature = createFeature({
name: sharedFeatureKey,
reducer: createReducer(
initialState,
on(SharedActions.setTitle, (state, { title }) => ({ ...state, title })),
),
});
and the registration in the module:
StoreModule.forFeature(fromShared.sharedFeature),
I can't really understand what I'm doing wrong and I can't find anyting on the internet.
EDIT:
After some experiments I found out that the cause seems to be related to the fact that the module is not tied to any route.
Defining a route for the module within the app.module solve the problem, but I already did something similar before (in Angular 8) and didn't have this kind of problem.
Did something changed with the latest versions?
EDIT2:
It's not the route, it happens when I try to dispatch an action from inside a component which reside in an other module. But this doesn't explain why dispatch inside the module still return the error if the module is not tied to a route.
Solution
As last resort I tried to create an other project excluding the standalone API (--standalone false
) and this seems to have solved the issue: now I can dispatch actions relative to a store which is in an imported Module.
Maybe standalone API and StoreModule.forFeature shouldn't be used together.
Answered By - Federico Xella
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.