NullInjectorError:没有 ReducerManager 的提供程序
2018-03-06
39073
我正在使用新的 ngrx 5。这是包含 Reducer 和 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 { }
我已经按照 本 教程进行操作
当我运行应用程序时,出现以下错误:
"StaticInjectorError(AppModule)[StoreFeatureModule -> ReducerManager]:
\n StaticInjectorError(Platform: core)[StoreFeatureModule -> ReducerManager]:
\n NullInjectorError: No provider for ReducerManager!"
但如果我在提供程序中提供 ReducerManager,则会收到此错误:
No provider for ReducerManagerDispatcher!
3个回答
通过在导入中添加
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 讨论。上述原因已在同一讨论中说明
suku
2018-03-06
我遇到了同样的问题,我找到了这个解决方案
imports: [
StoreModule.forRoot({}),
StoreModule.forFeature('filter-app', filterReducer)
]
Rotceh
2020-03-13
您还必须添加
EffectsModule.forRoot([]),
在项目 NgModule 的根目录中
dev-sn-27
2024-03-04