Angular Organization
App--appModule
appRouting
guards/
shared/
sharedModule
pipes/
models/
services/
containers/
containerA.component
components/
componentB.component
[core/]
actions/
reducers
effects/
selectors/
Feature--
featureModule
featureRouting
guards/
models/
services/
containers/
containerC.component
components/
componentD.component
[core/]
actions/
reducers
effects/
selectors/
. . .
Angular Import NgRx
npm install @ngrx/store @ngrx/effects @ngrx/store-devtools --save
// app.module.ts
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
// NgRx import
import { StoreModule, ActionReducer, MetaReducer } from '@ngrx/store';
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
import { EffectsModule } from '@ngrx/effects';
@NgModule({
imports: [
StoreModule.forRoot({}, ), //{metaReducers}
EffectsModule.forRoot([]),
StoreDevtoolsModule.instrument({
maxAge: 25, // Retains last 25 states
logOnly: environment.production // Restrict extension to log-only mode
}),
// ...
],
bootstrap: [AppComponent]
})
export class AppModule { }
NgRx modules
- @ngrx/store: RxJS powered state management for Angular applications, inspired by Redux
- @ngrx/effects: Side Effect model for @ngrx/store to model event sources as actions
- @ngrx/store-devtools: Store instrumentation that enables a powerful time-travelling debugger
- @ngrx/router-store: Bindings to connect the Angular Router to @ngrx/store
- @ngrx/entity: Entity State adapter for managing record collections
- @ngrx/schematics: Scaffolding library for Angular applications using NgRx