Search code examples
angularngrxngrx-store

nullinjectorerror no provider for store if importing the store module from a child module


In my app.module.ts file I set up a store with:

imports: [
  StoreModule.forRoot(
    { soundtrackState: soundtrackReducer }
  ),
  EffectsModule.forRoot(
    [
      // SoundtrackEffects TODO add some effects
    ]
  ),
  StoreDevtoolsModule.instrument({ maxAge: 15, logOnly: environment.production }),    
  CoreModule,

Now, if I move this code out and into the core.module.ts file then I get the nullinjectorerror no provider for store error.


Solution

  • for any other module that root you need to use forFeature and I guess app.module' store should be initialized with code you wrote.

    @NgModule({
      declarations: [
    
      ],
      imports: [
        EffectsModule.forFeature(groupModuleEffects),
        StoreModule.forFeature(GROUPS_FEATURE_NAME, groupModuleReducers),
        StoreDevtoolsModule.instrument({ maxAge: 25, logOnly: environment.production }),
        SharedModule
      ],
      providers: []
    })
    export class GroupsModule {}