in my feature module, im using the createReducer method to create my reducer as follow:
export const reducer = createReducer(
new InitState(),
on(loadData, state => {
return {
...state,
isLoading: true
};
})
);
but when i register the above reducer in the module class as following:
StoreModule.forFeature('my-module', reducer),
im getting the following error when compiling the project:
ERROR myModule.module.ts(38,47): Error during template compile of 'MyModuleModule' Function calls are not supported in decorators but 'createReducer' was called in 'reducer' 'reducer' calls 'createReducer' at myreducer.reducer.ts(14,24).
Does anyone know what might go wrong? or how do i register single reducer, because all the examples i have seen are using combineReducers with multiple reducers, and i wonder if for just one reducer, how do we do it?
Thank you much!
You need to wrap your reducer so that it is compatible with AOT compilation:
export function myAOTSafeReducer(
state: State | undefined,
action: Action
) {
return reducer(state, action);
}
Then refer to this exported named function in the state.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With