Problem:
After initializing the ngrx setup the DataPersistence service is not provided by the providers in app.module.ts but the AppEffects service is.
If I run my project I get an error because DataPersistence is used but nit provided.
zone.js:672 Unhandled Promise rejection: StaticInjectorError[DataPersistence]:
StaticInjectorError[DataPersistence]:
NullInjectorError: No provider for DataPersistence! ;
Solution:
After initializing the ngrx setup also add DataPersistence service to providers
@BioPhoton - plz show the code samples before and after.
Before:
@NgModule({
imports: [
BrowserModule,
RouterModule.forRoot(),
StoreModule.forRoot(
{ app: appReducer },
{
initialState: { app: appInitialState },
metaReducers: !environment.production ? [storeFreeze] : []
}
),
EffectsModule.forRoot([AppEffects]),
!environment.production ? StoreDevtoolsModule.instrument() : [],
StoreRouterConnectingModule
],
declarations: [
AppComponent,
],
providers: [AppEffects],
bootstrap: [AppComponent]
})
After:
@NgModule({
imports: [
BrowserModule,
RouterModule.forRoot(),
StoreModule.forRoot(
{ app: appReducer },
{
initialState: { app: appInitialState },
metaReducers: !environment.production ? [storeFreeze] : []
}
),
EffectsModule.forRoot([AppEffects]),
!environment.production ? StoreDevtoolsModule.instrument() : [],
StoreRouterConnectingModule
],
declarations: [
AppComponent,
],
// I provided DataPersistence here
providers: [AppEffects, DataPersistence],
bootstrap: [AppComponent]
})
@BioPhoton
Just looking for some more information here. Was this workspace created with create-nx-workspace or converted from a ng new workspace? This is probably a bug with the latter method.
Thank you
Can reproduce this with npm init nx-workspace name and adding ngrx via @nrwl/schematics in angular-console. At first I created an empty root store, afterwards I added a non-empty feature store. @BioPhoton's solution working.
Most helpful comment
Before:
After: