NullInjectorError:没有ReducerManager的提供者

问题描述 投票:0回答:3

我正在使用新的 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 { }

我已经遵循了这个教程

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

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

但是如果我确实在提供者中提供了ReducerManager,我会收到此错误:

No provider for ReducerManagerDispatcher!
angular ngrx-store ngrx-store-4.0
3个回答
75
投票

通过在导入中添加

StoreModule.forRoot({}),
设法解决了这个问题。

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

请查看这里关于此问题的 github 讨论。上述原因在同一个讨论中也说了


5
投票

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

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


0
投票

您还必须添加

EffectsModule.forRoot([]),

在项目的根目录中 NgModule

© www.soinside.com 2019 - 2024. All rights reserved.