Question presented to candidate:
"Explain Angular Signals to a developer who has only used plain class fields and RxJS. What are signal, computed and effect, and why did Angular add them?"
What a strong answer should cover:
- A signal is a wrapper around a value that tracks its readers; read by calling it, write with
setorupdate. computed()is a derived, lazy, memoised signal that re-runs only when a dependency it actually read changes.effect()runs side effects when signals it read change; it is for syncing with the outside world, not for deriving state.- Equality: setting an equal value notifies nobody; mutating an object in place is invisible; custom
equalis possible. untracked()reads without creating a dependency; writing a signal insidecomputedis an error (NG0600).- Why: fine-grained change detection without Zone.js, which is why v22 apps are zoneless and OnPush by default.
- History: developer preview in v16,
signal/computedstable in v17,effectstable in v20.
Clarifying questions expected:
- "Should I compare them with RxJS as well, or focus on the signal APIs?"
Code / implementation expected: Optional β a small component with a signal, a computed and an effect.