Skip to the page

Signals · mid

Signal inputs, linkedSignal and avoiding effect copies

Signal inputs are read with a call and only after Angular sets them. Derived values use computed; a derived value that the user can also change uses linkedSignal.

The notes

What you must know

  • input() and input.required() give a signal. Reading a required input before it is set (for example in the constructor) throws NG0950.
  • A value that depends on an input must be a computed, not a plain field. A plain field is calculated once and never updates.
  • An effect that copies one signal into another adds extra change detection rounds, can show a stale value for one render and can loop.
  • Since v19 an effect may write signals, but that does not make copying a good design.
  • linkedSignal is writable and recomputes when its source changes. Example: a selected slot resets when the list of slots changes.
  • computed is read-only, so it cannot hold a user choice.
  • A component that writes to its own input needs model() or a separate state.

The red pen

Common traps: mistake → fix

  • Mistake: I can use an effect to keep two signals equal

    Fix: use computed or linkedSignal.

  • Mistake: computed can be set by the user

    Fix: it is read-only.

Easy to hard

Questions interviewers ask, easy to hard

  1. What is NG0950?
  2. How do you keep a selected item valid when the list changes?
  3. Why is an effect that sets another signal a code smell?
  4. When do you choose linkedSignal over computed?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview