Search code examples
angulartypescriptngrxngrx-storengrx-store-4.0

How use forFeature not for lazy loaded modules?


How use forFeature in ngrx not for lazy loaded modules?

In my application, every module should have his own reducer

StoreModule.forFeature('feature', featureReducers, { metaReducers }),

How can I implement this?


Solution

  • So, in app.module.ts we mention for StoreModule.forRoot(reducer, {}) so which injects the store for the Main Application, when we are lazy loading a route, we need to add StoreModule.forFeature('lazyModule', reducer) in your Lazy Module and you need to import the module in the below format in your app routes file.

    { path: 'lazy', loadChildren: '../lazyComponent/lazy.module#LazyModule'},
    

    Then the reducer and in dynamically injected when we visit that route.