Angular Signals are a state management feature. It is used to simplify change detection, improve performance, and make Angular applications more predictable and easier to debug.
When a signal variable’s value changes, then Angular automatically updates the UI.
What is the benefit of Angular Signals?
1. Reducing unnecessary change detection.
2. Preparing Angular for a zone-less future (without Zone.js).
3. Automatic UI updates.
4. Better Performance
How to create a Signal?
To create a signal, you have to use the signal() function
import { signal } from '@angular/core';
count = signal(0);
In this example, I have created a count variable with a default value of 0.
How to get a Signal variable’s value?
You have to get the signal variable’s value through the signal variable name as a function. Suppose you have a count signal variable, then you need to get through count().
Example:
console.log(this.count()); // output: 0
How to Update a Signal?
We can update the signal through the set() or update() method.
Update Signal using the set() method
Suppose, you have to update the count value from 0 to 5 using the set() method.
this.count.set(5); //update value 5
this.count(); // get the count variable's value is 5
Update Signal using the update() method
Suppose, you have to update the count value from 0 to 5 using the set() method.
this.count.update(value => value + 5); //update value 5
Use Signals in Angular Templates
Suppose, you have to use a signal in an Angular template file.
Count: {{ count() }}
Example: Counter App Using Signals
@Component({
selector: 'app-counter',
template: `<h2>Count: {{ count() }}</h2>
<button (click)="increment()">+</button>`,
standalone: true
})
export class CounterComponent {
count = signal(0);
increment() {
this.count.update(v => v + 1);
}
}
Signals vs RxJS Observables
| Feature | Signals | Observables |
|---|---|---|
| Complexity | Simple | Moderate to High |
| Async Streams | ❌ | ✅ |
| Change Detection | Fine-grained | Global |
| State Management | Excellent | Possible |
| Learning Curve | Easy | Steeper |
Angular Signals – Interview Questions
Q 1: What are Angular Signals?
Ans: Signals are reactive primitives used to manage state changes efficiently.
Q 2: How do signals improve performance?
Ans: They update only affected components instead of triggering full change detection.
Q 3: What are computed signals?
Ans: Signals derived from other signals.
Q 4: What is effect in signals?
Ans: It runs side effects when signals change.
Q 5: Are signals replacing Observables?
Ans: No, they complement Observables but focus on local state management.
Angular Signals – Objective Questions (MCQs)
Q1. Angular Signals are used for:
Q2. Signals were introduced in:
Q3. Signal value is accessed using:
Q4. Signals replace:
Q5. Signals are: