NullInjectorError:没有ReducerManager的提供程序

时间:2018-03-06 09:23:55

标签: angular ngrx-store ngrx-store-4.0

我正在使用新的ngrx 5.这是包含reducers和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')

这是我导入storeModule的方式

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

export class AppModule { }

我已关注this教程

当我运行应用程序时,出现以下错误:

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

但如果我在提供商中提供ReducerManager,我会收到此错误:

No provider for ReducerManagerDispatcher!

2 个答案:

答案 0 :(得分:18)

通过在导入中添加{{1}}来管理解决此问题。

  

StoreModule.forRoot只应在项目NgModule的根目录中调用一次。如果您不想注册功能,请使用StoreModule.forFeature。使用forRoot注册Store所需的全局提供程序。

检查有关此问题的github讨论here。上述原因在同一讨论中阐述

答案 1 :(得分:1)

我遇到了同样的问题,并且找到了解决方案

imports: [
       StoreModule.forRoot({}), 
    StoreModule.forFeature('filter-app', filterReducer)
]