I am trying to use Ngxs only in one of my components in application. When I import NgxsModule.forRoot([]) in my child module where I will be using it I'm getting this error and whole application is not working:
Error: Uncaught (in promise): NullInjectorError: NullInjectorError: No provider for InjectionToken USER_PROVIDED_NGXS_EXECUTION_STRATEGY!
NullInjectorError: NullInjectorError: No provider for InjectionToken USER_PROVIDED_NGXS_EXECUTION_STRATEGY!
child-component.module.ts
@NgModule({
declarations: [
ChildComponentComponent
],
imports: [
NgxsModule.forRoot([]),
CommonModule,
NgxsModule.forRoot([ChildState], { developmentMode: isDevMode() }),
]
})
export class ChildComponentModule { }
this solution also not working
child-component.module.ts
@NgModule({
declarations: [
ChildComponentComponent
],
imports: [
CommonModule,
NgxsModule.forRoot([]),
NgxsModule.forFeature([ChildState]),
]
})
export class ChildComponentModule { }
When I import NgxsModule.forRoot([]) in app.module.ts everything is working.
app.module.ts
@NgModule({
declarations: [
AppComponent,
ChildComponentComponent
],
imports: [
BrowserModule,
NgxsModule.forRoot([]),
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
child-component.module
@NgModule({
declarations: [
ChildComponentComponent
],
imports: [
CommonModule,
NgxsModule.forFeature([ChildState]),
]
})
export class ChildComponentModule { }
Is there a way to resolve this issue and use ngxs only where I need it without importing it in app.module.ts Is importing in app.module.ts obligatory?