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.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
input()andinput.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
effectthat 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.
linkedSignalis writable and recomputes when its source changes. Example: a selected slot resets when the list of slots changes.computedis 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
computedorlinkedSignal.Mistake:
computedcan be set by the userFix: it is read-only.
Easy to hard
Questions interviewers ask, easy to hard
- What is NG0950?
- How do you keep a selected item valid when the list changes?
- Why is an effect that sets another signal a code smell?
- 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 voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.