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() === 30All lessons in this course
- Signal Stores in Services
- Deriving State with computed
- Updating State Immutably
- Connecting Signals and RxJS