linkedSignal()
A writable signal whose value is derived but can also be overridden locally.
Syntax
linkedSignal<T>(computation) | linkedSignal({ source, computation }) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
computation | function | No | Derives the value from source signals. |
source | function | No | Optional source whose change resets the linked value. |
Returns
WritableSignal<T> — A writable signal that recomputes when its source changes.
Examples
import { signal, linkedSignal } from '@angular/core';
const options = signal(['a', 'b', 'c']);
const selected = linkedSignal(() => options()[0]);
selected.set('b'); // local override
options.set(['x', 'y']); // resets to 'x'
Notes
linkedSignal behaves like computed (it derives from sources) but is writable,
so the user can override the derived value. When the source changes the value
recomputes, discarding the override. Ideal for selections that should reset
when the underlying list changes.