Angular 19 Signals Deep Dive: Reactive State Management Without RxJS
Angular 19 Signals Deep Dive: Reactive State Management Without RxJS
import { Component, signal, computed } from '@angular/core';
@Component({
selector: 'app-counter',
template: `
<p>Count: {{ count() }}</p>
<p>Doubled: {{ doubled() }}</p>
<button (click)="increment()">+1</button>
`
})
export class CounterComponent {
count = signal(0);
doubled = computed(() => this.count() * 2);
increment() {
this.count.update(v => v + 1);
}
}Angular 19 introduced a fully stable Signals API that fundamentally changes how we manage reactive state in Angular applications. If you have been relying heavily on RxJS for state management, Signals offer a simpler and more performant alternative for many common use cases.
What Are Signals?
Signals are reactive primitives that hold a value and notify consumers when that value changes. Unlike RxJS Observables, Signals are synchronous, glitch-free, and automatically tracked by Angular's change detection system.
Core Signal Types
1. signal() - Creates a writable signal that holds a value.
2. computed() - Derives a new signal from one or more existing signals. Automatically recalculates when dependencies change.
3. effect() - Runs side effects whenever the signals it reads change.
Example: Counter Component
import { Component, signal, computed } from '@angular/core';
@Component({
selector: 'app-counter',
template: `
<p>Count: {{ count() }}</p>
<p>Doubled: {{ doubled() }}</p>
<button (click)="increment()">+1</button>
`
})
export class CounterComponent {
count = signal(0);
doubled = computed(() => this.count() * 2);
increment() {
this.count.update(v => v + 1);
}
}
Great deep dive into Angular 19 Signals! The shift from RxJS to Signals for state management is a welcome change. Signals being synchronous and glitch-free makes them much easier to reason about compared to complex Observable chains. The migration tips are especially helpful - starting with BehaviorSubject replacements is a smart incremental approach. Looking forward to the fully zoneless Angular experience!