15

Problem: Error: No provider for Store!

I'm bootstraping store module in main.ts:

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

And injecting in to vehicle.component.ts:

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

Full source code is here: GitHub, last version running on GitHub Pages

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

3 Answers 3

14

I had this error because, in my component auto-import imported Store from import { Store } from '@ngrx/store/src/store' instead of import { Store } from '@ngrx/store'; . Anyway, this was in Angular 5

Sign up to request clarification or add additional context in comments.

2 Comments

Just had the same issue and didn't even notice it! Thanks for this post, you saved me some time :)
thanks, for some reason my auto import imported store from ngrx/store
11

In app.module.ts add:

// Make sure you import from @ngrx/store import { StoreModule } from '@ngrx/store'; @NgModule({ imports: [ StoreModule.forRoot({ characters, vehicles }), ... 

2 Comments

Should we pass the real reducers? As its just component testing
I'm not sure I follow, the answer was to fix a provider error. But for testing purposes I don't see why not to pass the actual reducers.
6

Just for sake of completeness, with Angular 5 / Ngrx 4.1.1 it would 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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.