Property 'replaceReducer' does not exist o

2019-08-20 20:31发布

问题:

In my Angular app, I have a function which replaces replaces the current reducer used by the Store. However, after upgrade from @ngrx/store v2.2.2 to v6.1.0, "replaceReducer" function seems to have been removed from the Store interface.

I've gone through the NGRX migration guide (https://github.com/ngrx/platform/blob/master/MIGRATION.md) hoping to find a possible solution or an alternative way to go around the issue but I can't find any reference to the removed "replaceReducer" function interface.

Here is my code:

export const accountingModuleReducer: ActionReducer<State> = createReducer(reducers);

export function accountingStoreFactory(appStore: Store<fromRoot.State>) {
  appStore.replaceReducer(accountingModuleReducer);
  return appStore;
}

回答1:

Replace Reducer has been deprecated. Checkout this issue to see an alternative way to approach this problem. Also checkout the StoreModule.forFeature() docs here, which might help you out.