Signals were introduced to make it easier and faster to track changes in data and update the UI accordingly. They simplify state management by automatically notifying when data changes.
Signals track which parts of the component use their value. When the value changes, only those parts update, making rendering more efficient.
Traditional Angular change detection runs checks broadly, often causing extra work. Signals track exactly what depends on what, so Angular updates only what changed, improving performance and removing the need for zone.js.
import { Component, signal } from '@angular/core'; @Component({ selector: 'app-counter', template: `<button (click)="increment()">Count: {{ count() }}</button>` }) export class CounterComponent { count = signal(0); increment() { this.count.update(c => c + 1); } }
The code imports signal, creates a signal with initial value 0, updates it with update(), and accesses it as a function in the template to reflect changes.
Signals are functions. To get their current value in the template, you must call them like count(). Using {{ count }} just shows the function reference, so the UI does not update.