NullInjectorError: No provider for ReducerManager

NullInjectorError: No provider for ReducerManager

我正在使用新的 ngrx 5。这是包含减速器和 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!

通过在导入中添加 StoreModule.forRoot({}), 设法解决了这个问题。

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.

查看关于此问题的 github 讨论 here。上面的原因在同一个讨论

我遇到了同样的问题,我找到了这个解决方案

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