Angular
Search…
What's NgRx
NgRx is a framework for building reactive applications in Angular. NgRx provides libraries for:
  • Managing global and local state.
  • Isolation of side effects to promote a cleaner component architecture.
  • Entity collection management.
  • Integration with the Angular Router.
  • Developer tooling that enhances developer experience when building many different types of applications.
To install NgRx we need:
1
ng add @ngrx/store
Copied!
and
1
ng add @ngrx/store-devtools
Copied!
This should be visible in your app.module.ts
1
StoreModule.forRoot(reducers, { metaReducers }),
2
StoreDevtoolsModule.instrument({ maxAge: 25, logOnly: environment.production })
Copied!
Once we need to add a store we should add the following command in our terminal. In our case we will add an auth/Auth store.
1
ng generate store auth/Auth --module auth.module.ts
Copied!
in the auth.module.ts we should see
1
StoreModule.forFeature('auth', fromAuth.reducers, { metaReducers: fromAuth.metaReducers }),
Copied!
Once we have completed such a section we should add our store in our component just like any other service in our constructor:
1
private store: Store<AppState>
Copied!
Coming from:
1
import { Store } from "@ngrx/store";
Copied!
Last modified 1yr ago
Copy link