Getting started and setting up NgRx
To use NgRx state management, we must install the @ngrx/store
library; this will contain all of the functions that will allow us to configure the store and create reducers and actions.
To install the @ngrx/store
library, we must execute the following command:
ng add @ngrx/store
The preceding command will perform the following steps:
- Update
package.json
by adding@ngrx/store
to the dependencies. - Run
npm install
to install the dependencies. - Update
src/app/app.module.ts
by addingStoreModule.forRoot(reducers, {})
to theimports
array.
Before executing this command, make sure that the version of @ngrx/store
is aligned with the version of your Angular; in our project, our Angular version is version 13.3.0
, which means that we need to use version 13 of @ngrx/store
.
Flags are also available that allow us to install @ngrx/store
with customizations. The following is the list of flags we can use:
--path
: Specifies...