Under The Hood
frontend angular Angular 19+ (linkedSignal)

linkedSignal(): Dependent Mutable State Synchronization

Last updated
Prerequisites:
Angular signals (signal, computed)
Understanding of derived vs mutable state
  • angular
  • signals
  • linkedSignal
  • state
  • synchronization
  • reactivity

Read at your depth

The practical view

A computed() is derived and read-only; a signal() is writable but independent. linkedSignal() is both: it derives its value from a source (a signal or computed) AND allows explicit writes — until the source changes, at which point it re-syncs to the source. const selectedId = linkedSignal(() => this.items()[0].id);. Reading selectedId() gives the current selection; selectedId.set(otherId) overrides it locally; when items() changes (source recomputed to a different first id), selectedId automatically resets to the new source value. Use it for 'selection that follows a list, but the user can override until the list changes'.

The same idea in other frameworks

react equivalent
The 'derived state reset' pattern in React (key-based remount or useEffect sync) is the analogue.

Legacy vs modern

Effect-based state reset vs linkedSignal

Syncing mutable state from a source via an effect is error-prone (loops, ordering); linkedSignal makes the re-sync declarative and atomic.

before → after
Effect + signal manual sync
selectedId = signal(''); // ❌ OLD
constructor() {
  effect(() => this.selectedId.set(this.items()[0]?.id ?? '')); // ❌ OLD: effect writes signal
linkedSignal declarative sync
selectedId = linkedSignal(() => this.items()[0]?.id ?? ''); // ✅ NEW

Interview gotchas

Context

This tests whether you understand the derived-vs-mutable distinction and the exact use case linkedSignal fills — interviewers want a precise line between the two primitives.

The mechanical answer

computed() is a pure, derived, read-only value: it recomputes from its dependencies and cannot be written. linkedSignal() is derived AND writable: it initializes from a source computation, but the user can call set()/update() to override the value locally. The override lasts until the source changes, at which point the value re-syncs to the new source output. Use computed() when the value is fully a function of other state (formatted text, filtered lists). Use linkedSignal() when you need a mutable piece of state that should reset to follow a changing source — selections, pagination page, expanded item ids, draft defaults. If you tried to use computed() for these, you could never let the user deviate; if you used a plain signal, you'd need an effect to reset it.

Trap

The naive answer is 'linkedSignal is a writable computed'. It is, but the write semantics matter: a write overrides until the source changes, then re-links. Another trap: assuming every source change resets the value — only source value changes (per equality) trigger re-link, and a manual set suppresses re-sync until the next source change. Candidates who articulate the reset-on-source-change semantics show real understanding.

Under The Hood — a multi-depth technical interview hub.

Third-party licenses Press ⌘ K to search.