computed()
Derives a memoized read-only signal from other signals.
Syntax
computed<T>(computation: () => T, options?): Signal<T> Parameters
| Name | Type | Required | Description |
|---|---|---|---|
computation | () => T | No | Function whose return value becomes the derived signal value. |
options | object | No | Optional config; supports an equal comparator function. |
Returns
Signal<T> — A read-only signal recomputed lazily when its dependencies change.
Examples
import { signal, computed } from '@angular/core';
const price = signal(100);
const qty = signal(3);
const total = computed(() => price() * qty());
console.log(total()); // 300
const firstName = signal('Ada');
const lastName = signal('Lovelace');
const fullName = computed(() => `${firstName()} ${lastName()}`);
Notes
Computed signals are lazy and memoized: the computation only runs when read
and when a tracked dependency has changed. They are read-only — you cannot
call set() or update() on them. Only signals read during the computation
become dependencies.