All Articles

Announcing NgRx 4

Announcing NgRx 4 There is a lot in this release that the team hopes you will enjoy. Some of the highlights:

  • Official support for lazy loading
  • Simplified testing
  • Redesigned router integration

Of course, there is a lot more great stuff in this release (the improved dev ergonomics and error messages for starters). So check out the ngrx platform repository to find out more.

Support for Lazy Loading

Even though it was always possible to use lazy loading with NgRx (see here), it was not easy: you had to manually manage loading and unloading reducers. With this release we’ve added official support for lazy loading.

@NgModule({
  imports: [
    StoreModule.forRoot(appReducers),
    EffectsModule.forRoot([SourceA, SourceB]),
    RouterModule.forRoot([
      { path: ‘lazy’, loadModule:./lazy.module#LazyModule’ }
    ])
  ]
})
export class AppModule { }
@NgModule({
  imports: [
    StoreModule.forFeature(‘lazy’, lazyReducers),
    EffectsModule.forFeature([SourceC]),
    RouterModule.forChild(childRoutes)
  ]
})
export class LazyModule { }

Similar to the Angular router, NgRx uses forRoot for the main NgModule, and forFeature for a lazy-loaded one.

Published 23 Aug 2017

Software & game developer.
cime on Twitter