NullInjectorError: No provider for ReducerManager

浪尽此生 提交于 2019-12-08 15:57:41

问题


I am using the new ngrx 5. This is the file that holds the reducers and the featureSelector:

import AppState from '../interfaces/app.state'
import { ActionReducerMap, createFeatureSelector } from '@ngrx/store'
import { partnerReducer } from './partner.reducer'

export const reducers: ActionReducerMap<AppState> = {
  partnerState: partnerReducer
}

export const getAppState = createFeatureSelector<AppState>('appState')

This is how I am importing the storeModule

@NgModule({
declarations: [...],
imports: [...
  RouterModule.forRoot(ROUTES),
  StoreModule.forFeature('appState', reducers)
],
providers: [...],
bootstrap: [AppComponent],
entryComponents: [...]
})

export class AppModule { }

I have followed this tutorial

When I run the app, I get the following error:

"StaticInjectorError(AppModule)[StoreFeatureModule -> ReducerManager]: 
\n  StaticInjectorError(Platform: core)[StoreFeatureModule -> ReducerManager]: 
\n    NullInjectorError: No provider for ReducerManager!"

But if I do provide ReducerManager in the providers, I get this error:

No provider for ReducerManagerDispatcher!

回答1:


Managed to solve this by adding StoreModule.forRoot({}), in the imports.

StoreModule.forRoot should only be called once in the root of your project NgModule. If you wan't to register a feature, use StoreModule.forFeature. Using forRoot registers the global providers needed for Store.

Check the github discussion here on this issue. The above reason was stated in the same discussion



来源:https://stackoverflow.com/questions/49127332/nullinjectorerror-no-provider-for-reducermanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!