Skip to content

Getting Started ​

@angular-redux2/store connects a Redux store to an Angular application. The state is an Angular signal, so a component reads it like any other signal: no async pipe, no subscription, and no decorator.

Install ​

bash
npm install @angular-redux2/store redux
bash
pnpm add @angular-redux2/store redux
bash
yarn add @angular-redux2/store redux

rxjs and @angular/core are peer dependencies that an Angular application already has. No tsconfig.json setting is needed.

Signals are built into the store: the state is an Angular signal, and every selection is a computed. See Signals for using them with computed, effect, and linkedSignal.

🔁 Coming from 5.x

Version 6 has no decorators. To keep @Select, @Dispatch, and @Substore while you migrate, add @angular-redux2/decorators. Migrating from 5.x explains why they moved and shows both styles side by side.

Describe the state ​

A slice holds one part of the state, its reducer, and one typed action creator per handler:

ts
import { combineReducers } from 'redux';
import { createSlice } from '@angular-redux2/store';

export const counter = createSlice('counter', 0, {
    increment: state => state + 1,
    add: (state, amount: number) => state + amount
});

export const rootReducer = combineReducers({ counter: counter.reducer });
export type AppState = ReturnType<typeof rootReducer>;

Configure the store ​

Add provideNgRedux to the application config:

ts
import type { ApplicationConfig } from '@angular/core';

import { isDevMode } from '@angular/core';
import { provideNgRedux } from '@angular-redux2/store';
import { rootReducer } from './store';

export const appConfig: ApplicationConfig = {
    providers: [
        provideNgRedux({ reducer: rootReducer, devTools: isDevMode(), freeze: isDevMode() })
    ]
};
OptionNotes
reducerThe root reducer.
initialStateThe state that the store starts from. Leave it out when the reducers have defaults.
middlewareRedux middleware, such as a thunk or a logger.
enhancersRedux store enhancers, applied after the middleware.
devToolstrue or extension options to connect Redux DevTools.
freezetrue freezes every state, so a mutation throws. Pass isDevMode().
transferStatetrue carries the state from server-side rendering to the browser.

The store is created the first time something injects it, and it is ready at that moment.

Read and write state ​

ts
import { Component, inject } from '@angular/core';
import { injectSelect, NgRedux } from '@angular-redux2/store';
import { counter, type AppState } from './store';

@Component({
    selector: 'app-counter',
    template: `
        <p>{{ count() }}</p>
        <button (click)="increment()">+1</button>
    `
})
export class Counter {
    private readonly store = inject(NgRedux<AppState>);

    readonly count = injectSelect((state: AppState) => state.counter);

    increment(): void {
        this.store.dispatch(counter.actions.increment());
    }
}

injectSelect returns a read-only signal. Annotate the selector parameter with the state type, and TypeScript infers the selected type. dispatch sends an action, and the signal holds the new value as soon as it returns.

Where to go next ​

  • Example - a complete application with every feature and a unit test.
  • NgRedux - the store, select, select$, and the store options.
  • Signals - selections with computed, effect, linkedSignal, and inputs.
  • Selectors - signals, observables, and when a selection updates.
  • Sub-stores - a store scoped to one branch of the state.
  • Slices - reducers with typed action creators.
  • Draft state - mutating state inside a reducer.
  • Mocks - testing components that use the store.
  • Migrating from 5.x - from decorators to signals.
  • Design decisions - what was removed or left out, and why.
  • Benchmarks - version 6 against 5.0.2.

Released under the Mozilla Public License 2.0