0Pricing
Angular Academy · Lesson

Computed and Methods

Add derived state and update methods.

Beyond Raw State

A useful store exposes derived values and behavior. SignalStore adds these with withComputed for read models and withMethods for actions.

withComputed

withComputed receives the store's current signals and returns an object of computed() signals. They memoize and auto-update like any computed.

import { signalStore, withState, withComputed } from '@ngrx/signals';
import { computed } from '@angular/core';

export const CartStore = signalStore(
  withState({ items: [] as Item[] }),
  withComputed(({ items }) => ({
    count: computed(() => items().length),
    total: computed(() => items().reduce((s, i) => s + i.price, 0))
  }))
);

All lessons in this course

  1. Creating a SignalStore
  2. Computed and Methods
  3. rxMethod for Async Work
  4. Entities and Custom Features
← Back to Angular Academy