FresherTechnicalAngular
What are signals in Angular and how do you read and update one?
Try answering first
Model answer
A signal is a value holder that tells Angular when it changes. You create one with signal(initialValue), read it by calling it like a function, and write it with set or update.
import { signal } from '@angular/core'
const count = signal(0)
console.log(count()) // 0
count.set(5)
count.update((n) => n + 1)
console.log(count()) // 6
set(value)replaces the value.update(fn)computes the new value from the old one.asReadonly()gives a read-only view you can expose from a service.
In a template you write {{ count() }}. Angular records that the template read the signal, so when count changes it knows exactly which view to refresh. That is called fine-grained reactivity, and it is what makes zoneless change detection possible.
Signals work well for state and derived values with computed.
Always read a signal with parentheses, and update it with set or update.
Key points
- Create with signal(), read by calling it
- Write with set or update
- Templates track which signals they read
- asReadonly exposes state safely
Likely follow-ups
- How does a signal differ from a plain class property?
Common mistakes
- Forgetting the parentheses and rendering the signal function
- Mutating an object inside a signal without setting a new value