我正在修改现有的项目以实现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`发布于 2018-11-01 10:00:48
您需要在导入NgReduxModule下添加module.ts
imports: [
NgReduxModule
]https://stackoverflow.com/questions/53098747
复制相似问题