我正在修改现有项目以实现 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`