Error: There is no provider for the Store! when trying @ ngrx / store with Angular 4.0

Problem: Error: no provider for the store!

I load the storestripping module in main.ts:

platformBrowserDynamic().bootstrapModule(AppModule,[ provideStore({ characters, vehicles }) ]); 

And by typing in auto.component.ts:

 constructor( private _route: ActivatedRoute, private _router: Router, private _vehicleService: VehicleService, private _store: Store<any> ) {} 

The full source code is here: GitHub , the latest version works on GitHub pages

PS. Adding Store to providers leads to another error: Unable to resolve all parameters for Store: (?,?,?).

+7
angular ngrx ngrx-store
source share
3 answers

In app.module.ts add:

 import { Store, StoreModule } from '@ngrx/store'; @NgModule({ imports: [ StoreModule.provideStore({ characters, vehicles }), ... 
+5
source share

I had this error because in my automatic component import, the Store imported from import { Store } from '@ngrx/store/src/store' instead of import { Store } from '@ngrx/store' Anyway, this was in angular 5

+10
source share

Just for completeness, with Angular 5 / Ngrx 4.1.1 it will be (in app.module.ts):

 import { StoreModule } from '@ngrx/store'; import { reducers } from './reducers/reducers'; @NgModule({ imports: [ StoreModule.forRoot(reducers), ... ], ... 

There is a complete example here

0
source share

All Articles