Lazy Loading Store into a standalone component. #2104
-
Currently the documentation on Lazy Loading (v3.8.2) describes the process for Lazy Loaded modules: @NgModule({
imports: [NgxsModule.forFeature([LazyState])]
})
export class LazyModule {} I am looking for something similar for a lazy loaded standalone component (Angular V17), because currently if i do something like this @Component({
selector: 'test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.scss'],
standalone: true,
imports: [
CommonModule,
NgxsModule.forFeature([LazyState])
],
}) I get the error:
Is there a way to achieve this, without adding the same state to the |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
It doesn't seem to be possible now. Theoretically getFeatureProviders() could be used for this but it's neither exported for public use, nor any of the standalone features like provideStore are released yet. |
Beta Was this translation helpful? Give feedback.
-
The In your case, you can have a separate module that imports the NGXS feature module, and then you import this module into the component: @NgModule({
imports: [NgxsModule.forFeature([LazyState])]
})
export class LazyModule {}
@Component({
selector: 'test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.scss'],
standalone: true,
imports: [
CommonModule,
LazyModule // <----- not `NgxsModule.forFeature`
],
}) |
Beta Was this translation helpful? Give feedback.
-
We considered providing states on components. However, this would entail having a local state at the component level rather than a global one. There is no technical option to provide global states at the component level, as we need to register those states within the global "states registry.". Additionally, when there's anything in the component |
Beta Was this translation helpful? Give feedback.
The
provideStore
andprovideStates
(standalone features available under thedev
version) will also not allow providing states on components since they return environment providers. That would be possible to use on theApplicationConfig
when bootstrapping the app andRoute
providers.In your case, you can have a separate module that imports the NGXS feature module, and then you import this module into the component: