/frontend-angular:angular-statefrom frontend-angular
Angular state management patterns including Signals, RxJS services, NgRx Store, NgRx SignalStore, and a decision tree for choosing the right approach.
Ships in frontend-angular. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Choose the right state management approach based on scope and complexity:
Is the state local to a single component?
YES → Angular Signals (signal, computed, effect)
Is the state shared across a few components in the same feature?
YES → Injectable Service with Signals (or BehaviorSubject if RxJS streams are needed)
Is the state shared across the whole app, or does it involve complex
async flows, undo/redo, time-travel debugging, or server sync?
YES → NgRx Store (Actions, Reducers, Effects, Selectors)
OR NgRx SignalStore (simpler API, signal-based)
Never reach for NgRx for local or simple shared state. Start simple, escalate only when needed.
import { signal, computed, effect, Signal, WritableSignal } from '@angular/core';
// Writable signal
const count = signal(0);
// Read
count(); // 0
// Write
count.set(5);
count.update(n => n + 1);
// Mutate in place (objects/arrays)
const items = signal<string[]>([]);
items.mutate(arr => arr.push('new item'));
// Derived (read-only, memoized)
const doubled = computed(() => count() * 2);
// Side-effect
const cleanup = effect(() => {
console.log('count is now', count());
// Optional cleanup
return () => console.log('cleanup');
});
@Component({
standalone: true,
template: `
<p>{{ count() }}</p>
<p>{{ doubled() }}</p>
<button (click)="increment()">+</button>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CounterComponent {
count = signal(0);
doubled = computed(() => this.count() * 2);
increment() {
this.count.update(n => n + 1);
}
}
Bridge between Signals and RxJS:
import { toSignal, toObservable } from '@angular/core/rxjs-interop';
@Component({ standalone: true, ... })
export class SearchComponent {
private searchService = inject(SearchService);
query = signal('');
// Observable → Signal (auto-unsubscribes)
results = toSignal(
toObservable(this.query).pipe(
debounceTime(300),
distinctUntilChanged(),
switchMap(q => this.searchService.search(q)),
),
{ initialValue: [] }
);
}
Injectable services centralizing shared state with BehaviorSubject / Observable.
@Injectable({ providedIn: 'root' })
export class CartService {
private items$ = new BehaviorSubject<CartItem[]>([]);
// Public read-only observable
readonly cart$ = this.items$.asObservable();
readonly count$ = this.items$.pipe(map(items => items.length));
readonly total$ = this.items$.pipe(
map(items => items.reduce((sum, i) => sum + i.price * i.quantity, 0))
);
addItem(item: CartItem) {
this.items$.next([...this.items$.value, item]);
}
removeItem(id: string) {
this.items$.next(this.items$.value.filter(i => i.id !== id));
}
clear() {
this.items$.next([]);
}
}
Option A — async pipe (Observable-native):
<p>{{ (cart.count$ | async) }} items</p>
@for (item of (cart.cart$ | async) ?? []; track item.id) {
<app-cart-item [item]="item" />
}
Option B — toSignal (preferred with OnPush):
@Component({ standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, ... })
export class CartComponent {
private cart = inject(CartService);
items = toSignal(this.cart.cart$, { initialValue: [] });
count = toSignal(this.cart.count$, { initialValue: 0 });
}
Replace BehaviorSubject with signals inside the service:
@Injectable({ providedIn: 'root' })
export class CartService {
private items = signal<CartItem[]>([]);
readonly cart = this.items.asReadonly();
readonly count = computed(() => this.items().length);
readonly total = computed(() =>
this.items().reduce((sum, i) => sum + i.price * i.quantity, 0)
);
addItem(item: CartItem) {
this.items.update(arr => [...arr, item]);
}
removeItem(id: string) {
this.items.update(arr => arr.filter(i => i.id !== id));
}
}
Use for complex global state, cross-cutting concerns, or when you need devtools / time-travel.
// app.config.ts
import { provideStore } from '@ngrx/store';
import { provideEffects } from '@ngrx/effects';
import { provideStoreDevtools } from '@ngrx/store-devtools';
import { productsReducer } from './products/state/products.reducer';
import { ProductsEffects } from './products/state/products.effects';
export const appConfig: ApplicationConfig = {
providers: [
provideStore({ products: productsReducer }),
provideEffects(ProductsEffects),
provideStoreDevtools({ maxAge: 25, logOnly: !isDevMode() }),
],
};
// products.actions.ts
import { createActionGroup, emptyProps, props } from '@ngrx/store';
import { Product } from '../product.model';
export const ProductsActions = createActionGroup({
source: 'Products',
events: {
'Load Products': emptyProps(),
'Load Products Success': props<{ products: Product[] }>(),
'Load Products Failure': props<{ error: string }>(),
'Select Product': props<{ id: string }>(),
},
});
// products.reducer.ts
import { createFeature, createReducer, on } from '@ngrx/store';
import { ProductsActions } from './products.actions';
import { Product } from '../product.model';
interface ProductsState {
products: Product[];
selectedId: string | null;
loading: boolean;
error: string | null;
}
const initialState: ProductsState = {
products: [],
selectedId: null,
loading: false,
error: null,
};
export const productsFeature = createFeature({
name: 'products',
reducer: createReducer(
initialState,
on(ProductsActions.loadProducts, state => ({ ...state, loading: true, error: null })),
on(ProductsActions.loadProductsSuccess, (state, { products }) => ({
...state,
products,
loading: false,
})),
on(ProductsActions.loadProductsFailure, (state, { error }) => ({
...state,
loading: false,
error,
})),
on(ProductsActions.selectProduct, (state, { id }) => ({
...state,
selectedId: id,
})),
),
});
export const { selectProductsState, selectProducts, selectLoading, selectError } =
productsFeature;
Use @ngrx/entity for normalized collections:
import { createEntityAdapter, EntityState } from '@ngrx/entity';
interface ProductsState extends EntityState<Product> {
loading: boolean;
error: string | null;
}
const adapter = createEntityAdapter<Product>();
const initialState = adapter.getInitialState({ loading: false, error: null });
const reducer = createReducer(
initialState,
on(ProductsActions.loadProductsSuccess, (state, { products }) =>
adapter.setAll(products, { ...state, loading: false })
),
);
export const { selectAll, selectEntities, selectIds, selectTotal } =
adapter.getSelectors();
// products.selectors.ts
import { createSelector } from '@ngrx/store';
import { productsFeature } from './products.reducer';
import { selectAll } from './products.reducer';
export const selectAllProducts = createSelector(
productsFeature.selectProductsState,
selectAll
);
export const selectSelectedProduct = createSelector(
productsFeature.selectProductsState,
productsFeature.selectSelectedId,
selectEntities,
(_, selectedId, entities) => (selectedId ? entities[selectedId] : null)
);
// products.effects.ts
import { inject } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { catchError, map, of, switchMap } from 'rxjs';
import { ProductsActions } from './products.actions';
import { ProductService } from '../product.service';
export class ProductsEffects {
private actions$ = inject(Actions);
private productService = inject(ProductService);
loadProducts$ = createEffect(() =>
this.actions$.pipe(
ofType(ProductsActions.loadProducts),
switchMap(() =>
this.productService.getAll().pipe(
map(products => ProductsActions.loadProductsSuccess({ products })),
catchError(err =>
of(ProductsActions.loadProductsFailure({ error: err.message }))
)
)
)
)
);
}
@Component({ standalone: true, ... })
export class ProductListComponent implements OnInit {
private store = inject(Store);
products = toSignal(this.store.select(selectAllProducts), { initialValue: [] });
loading = toSignal(this.store.select(productsFeature.selectLoading), { initialValue: false });
ngOnInit() {
this.store.dispatch(ProductsActions.loadProducts());
}
select(id: string) {
this.store.dispatch(ProductsActions.selectProduct({ id }));
}
}
Lighter-weight signal-based store with a simpler API. Good for feature-level state with NgRx patterns.
import { signalStore, withState, withComputed, withMethods, patchState } from '@ngrx/signals';
import { withEntities, setAllEntities } from '@ngrx/signals/entities';
import { rxMethod } from '@ngrx/signals/rxjs-interop';
type ProductsState = { loading: boolean; error: string | null };
export const ProductsStore = signalStore(
{ providedIn: 'root' },
withState<ProductsState>({ loading: false, error: null }),
withEntities<Product>(),
withComputed(({ entities }) => ({
productCount: computed(() => entities().length),
})),
withMethods((store, productService = inject(ProductService)) => ({
loadProducts: rxMethod<void>(
pipe(
tap(() => patchState(store, { loading: true })),
switchMap(() =>
productService.getAll().pipe(
tapResponse(
products => patchState(store, setAllEntities(products), { loading: false }),
err => patchState(store, { loading: false, error: String(err) })
)
)
)
)
),
}))
);
Usage in component:
@Component({ standalone: true, providers: [ProductsStore], ... })
export class ProductListComponent {
private store = inject(ProductsStore);
products = this.store.entities;
loading = this.store.loading;
ngOnInit() {
this.store.loadProducts();
}
}
| Scope | Complexity | Solution |
|---|---|---|
| Single component | Any | Signals |
| Feature (few components) | Low-Medium | Injectable Service + Signals |
| Feature (few components) | Medium (needs RxJS streams) | Injectable Service + BehaviorSubject |
| Global / Cross-feature | High | NgRx Store |
| Feature-level with NgRx patterns | Medium | NgRx SignalStore |
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub gagandeepp/software-agent-teams --plugin frontend-angular7 skills in this plugin
/angular-componentsAngular component patterns including standalone components, signals, directives, pipes, content projection, view queries, lifecycle hooks, and change detection strategies./angular-data-fetchingAngular data fetching patterns including HttpClient, interceptors, resolvers, RxJS operators, caching, loading/error state management, and SSR TransferState./angular-project-structureAngular workspace structure including Angular CLI, Nx monorepos, feature module organization, shared/core conventions, lazy-loaded routes, library projects, environment config, and barrel exports./angular-routingAngular Router configuration including lazy loading, route guards, nested routes, route params, navigation, resolvers, preloading strategies, and functional guards./angular-stylingAngular styling patterns including Prismatic Angular (org default UI library), Angular Material, Bootstrap, SCSS scoped styles, ViewEncapsulation, Tailwind, responsive design, and theming with CSS custom properties./angular-testingAngular testing with Jest and jest-preset-angular, Angular TestBed for component/service/pipe testing, DI mocking, signals testing, RxJS testing, Playwright E2E, and coverage requirements.