0Pricing
Angular Academy · Lesson

Deriving State with computed

Build read models from base state.

Derived State

Often state is computed from other state: a total from items, a filtered list, a validity flag. Angular's computed() creates a read-only signal whose value is derived from other signals.

Creating a computed

Pass a function to computed(). It reads other signals and returns a value. The result re-evaluates only when one of its dependencies changes.

import { signal, computed } from '@angular/core';

const price = signal(10);
const qty = signal(3);
const total = computed(() => price() * qty());
// total() === 30

All lessons in this course

  1. Signal Stores in Services
  2. Deriving State with computed
  3. Updating State Immutably
  4. Connecting Signals and RxJS
← Back to Angular Academy