Installation
npm install @ngrx/store --save
yarn add @ngrx/store
If your project is using the Angular CLI 6+ then you can install the Store to your project with the following ng add command :
ng add @ngrx/store@latest
- path - path to the module that you wish to add the import for the StoreModule to.
- project - name of the project defined in your angular.json to help locating the module to add the StoreModule to.
- module - name of file containing the module that you wish to add the import for the StoreModule to. Can also include the relative path to the file. For example, src/app/app.module.ts;
- minimal - By default true, flag to only provide minimal setup for the root state management. Only registers StoreModule.forRoot() in the provided module with an empty object, and default runtime checks.
- statePath - The file path to create the state in. By default, this is reducers.
- stateInterface - The type literal of the defined interface for the state. By default, this is State.
This command will automate the following steps:
- Update package.json > dependencies with @ngrx/store.
- Run npm install to install those dependencies.
- Update your src/app/app.module.ts > imports array with StoreModule.forRoot({}).
ng add @ngrx/store@latest --minimal false
This command will automate the following steps:
- Update package.json > dependencies with @ngrx/store.
- Run npm install to install those dependencies.
- Create a src/app/reducers folder, unless the statePath flag is provided, in which case this would be created based on the flag.
- Create a src/app/reducers/index.ts file with an empty State interface, an empty reducers map, and an empty metaReducers array. This may be created under a different directory if the statePath flag is provided.
- Update your src/app/app.module.ts > imports array with StoreModule.forRoot(reducers, { metaReducers }). If you provided flags then the command will attempt to locate and update module found by the flags.