@nx/angular:ngrx

Adds NgRx support to an application or library.

Usage

nx generate ngrx ...

By default, Nx will search for ngrx in the default collection provisioned in workspace.json.

You can specify the collection explicitly as follows:

Show what will be generated without writing to disk:

nx g ngrx ... --dry-run

Examples

Add root ngrx configration to the my-app application:

nx g @nx/angular:ngrx --root --parent=apps/my-app/src/app/app.module.ts --facade=false placeholder
Nx 15 and lower use @nrwl/ instead of @nx/

Add a users state with a facade to the my-lib library. It will be tracked under the default +state folder in the lib:

nx g @nx/angular:ngrx --parent=libs/my-lib/src/lib/my-lib.module.ts --facade=true --root=false users
Nx 15 and lower use @nrwl/ instead of @nx/

Add a root state configuration to my-app when my-app uses Standalone APIs:

nx g @nx/angular:ngrx --parent=apps/my-app/src/app/app.config.ts --root
Nx 15 and lower use @nrwl/ instead of @nx/

Add a users feature state to the Route definition of a library using Standalone APIs:

nx g @nx/angular:ngrx --parent=libs/my-lib/src/lib.routes.ts users
Nx 15 and lower use @nrwl/ instead of @nx/

Options

name

Required
string

Name of the NgRx feature state, such as products or users. Recommended to use the plural form of the name.

parent

string

The path to the file where the state will be registered. For NgModule usage, this will be your app.module.ts for your root state, or your Feature Module for feature state. For Standalone API usage, this will be your app.config.ts file for your root state, or the Routes definition file for your feature state. The host directory will create/use the new state directory. Note: The Standalone API usage is only supported in Angular versions >= 14.1.0.

root

boolean
Default: false

Setup root or feature state management with NgRx.

barrels

boolean
Default: false

Use barrels to re-export actions, state and selectors.

directory

string
Default: +state

The name of the folder used to contain/group the generated NgRx files.

facade

boolean
Default: false

Create a Facade class for the the feature.

minimal

boolean
Default: true

Only register the root state management setup or feature state.

route

string
Default: ''

The route that the Standalone NgRx Providers should be added to. Note: This is only supported in Angular versions >= 14.1.0.

skipImport

boolean
Default: false

Generate NgRx feature files without registering the feature in the NgModule.

skipFormat

boolean
Default: false

Skip formatting files.

skipPackageJson

boolean
Default: false

Do not update the package.json with NgRx dependencies.

module

Deprecated
string

The path to the NgModule where the feature state will be registered. The host directory will create/use the new state directory.

This option will be removed in a future version of Nx. Please switch to using --parent instead.