WritableSignal.update()
Computes a writable signal's next value from its current value.
Syntax
update(updateFn: (current: T) => T): void Parameters
| Name | Type | Required | Description |
|---|---|---|---|
updateFn | (current: T) => T | No | Function receiving the current value and returning the next one. |
Returns
void — Nothing; consumers are notified if the value changed.
Examples
import { signal } from '@angular/core';
const count = signal(0);
count.update((n) => n + 1);
const list = signal<string[]>([]);
list.update((arr) => [...arr, 'item']);
Notes
Prefer update() over set() when the next value depends on the current one;
it avoids reading the signal separately. Return a new reference for objects
and arrays so equality detects the change and consumers re-run.