1.5 KiB
1.5 KiB
Standalone APIs with NgRx and Angular 15
Standalone APIs were added to version 15 of NgRx, allowing for easier usage of NgRx with Standalone Components in Angular.
They must be added to routes definitions as they need to be added to the Environment Injector (https://ngrx.io/api/store/provideStore).
Nx will use these Standalone APIs when:
- Standalone APIs are supported
- Angular 15 is installed
This guide will show you how to leverage this using the NgRx generator.
{% callout type="check" title="Prerequisites" %}
Before following along with this guide, ensure you have:
- An Nx >= 15.6.0 Workspace with
@nx/angularinstalled - Angular 15 must be installed
{% /callout %}
Steps
- Generate an Angular application with Standalone Components and routing
nx g @nx/angular:app testapp --standalone --routing
- Generate NgRx Root State
{% tabs %} {% tab label="Nx Standalone Repo" %}
nx g @nx/angular:ngrx --root --parent=testapp/src/main.ts
{% /tab %} {% tab label="Nx Integrated Monorepo" %}
nx g @nx/angular:ngrx --root --parent=apps/testapp/src/main.ts
{% /tab %} {% /tabs %}
- Generate NgRx Feature State
{% tabs %} {% tab label="Nx Standalone Repo" %}
nx g @nx/angular:ngrx users --parent=testapp/src/app/app.routes.ts
{% /tab %} {% tab label="Nx Integrated Monorepo" %}
nx g @nx/angular:ngrx users --parent=apps/testapp/src/app/app.routes.ts
{% /tab %} {% /tabs %}