A computed total
Keep quantity and unit price as the inputs. Derive the total so neither input change leaves a stale value behind:
import {signal, computed} from '@angular/core';
const quantity = signal(0);
const unitPrice = signal(12);
const total = computed(() => quantity() * unitPrice());
quantity.update(value => value + 3);
console.log(total()); // 36
unitPrice.set(15);
console.log(total()); // 45
set replaces the value. update calculates its replacement from the current value. computed is read-only, so total.set(45) is a type error. In a component template, {{ total() }} reads the value; omitting the call refers to the signal function.
Dependencies and equality
A computed value tracks signals read while its calculation runs. A branch that doesn’t read a signal doesn’t depend on it for that calculation. Test both branches when a display switches between a fixed value and a calculated value.
Signals use referential equality by default. Mutating an array in place doesn’t create a new array reference. To add a row, return a new array with rows.update(current => [...current, newRow]). A read-only signal prevents writes through its signal API; it doesn’t freeze objects inside the value.
Effects and Observable streams
Use computed to express a derived value. An effect suits a side effect such as updating a nonreactive API, rather than keeping a second writable copy of the same total in sync. For asynchronous streams, Angular still works with RxJS. toSignal subscribes to an Observable and exposes its latest value as a signal; supply an initial value when the stream doesn’t emit synchronously.
Create that bridge once and reuse it.
Recreating it repeatedly can create repeated subscriptions.
A signal practice task
Add a discount signal to the example. A discount of 0 must preserve the total; changing quantity, price or discount must update the result. Then clear a list rendered from a signal and confirm its empty state appears. The Angular exercises give further cases. Return to the Angular course for checked component work, or rehearse the explanation with the interview questions.