得到错误-NullInjectorError:NgRedux没有提供程序!集成redux实现时

时间:2018-11-01 09:48:39

标签: angular redux ngredux

我正在修改现有项目以实现redux实现。进行代码更改,并在编译时发现以下错误。根据我参考的学习材料,无需将ngRedux添加到提供程序中。将其添加到提供程序后,仍然会出错。

 **AppModule.ts**
    //Activation of store.
    import {NgRedux , NgReduxModule} from '@angular-redux/store';
    import {IAppState,INITIAL_STATE,rootReducer} from '../store';
    //Other Imports here 
    @NgModule({
      declarations: [
        AppComponent,
        ViewallComponent,
        WorkoutComponent,
        CategoryComponent,
        TrackComponent,
        TestComponent,
        CategoryPipe,
        ActiveworkoutComponent,
        WorkoutPipe,
      ],
      imports: [
        BrowserModule,
        AppRoutingModule,
        FormsModule,
        ReactiveFormsModule,
        HttpModule,
        FusionChartsModule.forRoot(FusionCharts, Charts, FintTheme)
      ],
      providers: [
        WorkoutService,
        CategoryService,
        ActiveworkoutService
      ],
      bootstrap: [AppComponent]

    })

    export class AppModule { 
      constructor (ngRedux: NgRedux<IAppState>) {
           ngRedux.configureStore(rootReducer, INITIAL_STATE);
        }

    }

对组件进行了适当的更改,并制作了存储文件。

错误:

Error: StaticInjectorError(AppModule)[AppModule -> NgRedux]: 
  StaticInjectorError(Platform: core)[AppModule -> NgRedux]: 
    NullInjectorError: No provider for NgRedux!
Stack trace:
./node_modules/@angular/core/fesm5/core.js/NullInjector.prototype.get@http://localhost:4200/vendor.js:33896:19
resolveToken@http://localhost:4200/vendor.js:34133:17
tryResolveToken@http://localhost:4200/vendor.js:34077:16
./node_modules/@angular/core/fesm5/core.js/StaticInjector.prototype.get@http://localhost:4200/vendor.js:33974:20
resolveToken@http://localhost:4200/vendor.js:34133:17
tryResolveToken@http://localhost:4200/vendor.js:34077:16`enter code here`

1 个答案:

答案 0 :(得分:1)

您需要在导入的module.ts下添加 NgReduxModule

imports: [
    NgReduxModule
]