Angular Signals: A Minimal State Architecture
Use Angular signals for local state, keep untrusted data at a controlled boundary, and verify effects before shipping.
13 Jan 2026, 01:39 UTC

The problem and the useful takeaway
Angular applications often rely on mutable component properties and zone.js change detection. That works, but it makes it hard to know which piece of state triggered a refresh, and it checks more of the component tree than necessary.
Takeaway: keep writable state in a single injectable signal service, expose derived values with computed(), run side effects with effect(), and treat untrusted async data as an external boundary rather than part of the signal graph.
Requirements
- Angular 16 or later. Confirm with
ng versionin the project root. - State that is read in templates or shared between components.
- A clear boundary for data that comes from HTTP, localStorage, or third-party scripts.
A signal is a value wrapper that tells Angular when it is read and when it changes. computed() derives a new signal from other signals. effect() runs a side effect whenever its signal dependencies change. zone.js is Angular's default change-detection mechanism; signals can reduce reliance on it for local state.
Smallest suitable design
One domain service holds writable signals. Components receive the service through inject(), bind to read-only signals, and call service methods to mutate state. This prevents components from mutating each other's state directly.
import { inject, Injectable, signal, computed } from '@angular/core';
export interface CounterState {
value: number;
}
@Injectable({ providedIn: 'root' })
export class CounterService {
private readonly _value = signal(0);
readonly value = this._value.asReadonly();
readonly doubled = computed(() => this._value() * 2);
increment() {
this._value.update((current) => current + 1);
}
}
import { Component, inject, effect } from '@angular/core';
import { CounterService } from './counter.service';
@Component({
selector: 'app-counter',
template: `
<button (click)="service.increment()">Increment</button>
<span>{{ service.value() }}</span>
<span>{{ doubled() }}</span>
`,
})
export class CounterComponent {
readonly service = inject(CounterService);
readonly doubled = this.service.doubled;
constructor() {
effect(() => {
console.log('current value', this.service.value());
});
}
}
In this design, CounterComponent never writes to _value. It only reads value and asks the service to increment. The effect() logs changes without manually triggering change detection.
Trust and data boundaries
Signals do not sanitize values. Data from HTTP responses, URL parameters, or user-generated content is untrusted until it passes through a boundary. Bind such data through toSignal() or resource() so it enters the signal graph through a controlled initializer, and sanitize HTML with DomSanitizer before binding to innerHTML or event attributes.
import { Component, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { toSignal } from '@angular/core/rxjs-interop';
@Component({
selector: 'app-profile',
template: `<div *ngIf="user() as u">{{ u.name }}</div>`,
})
export class ProfileComponent {
private readonly http = inject(HttpClient);
readonly user = toSignal<{ name: string } | null>(
this.http.get<{ name: string }>('/api/user'),
{ initialValue: null },
);
}
Check the installed Angular release before using resource(); its signature and stability have changed between versions.
Operational checks
- Version check. Run
ng versionin the project root. No special permissions are required. Expected output: Angular 16 or later. Risk: none. - Unit test. Add
src/app/counter.service.spec.tsand runng test. Update the writable signal and assert the computed signal changes synchronously without calling change detection manually. Risk: an incomplete TestBed setup can produce false negatives. - DevTools inspection. Open Angular DevTools in the browser, inspect signal dependencies, and confirm
effect()cleanup runs when the host component is destroyed. Risk: leaked effect subscriptions if cleanup is missing. - SSR hydration check. Guard browser-only signal initializers with
isPlatformBrowser(platformId, PLATFORM_ID), then compare server-rendered HTML with client HTML. Risk: a mismatch produces hydration errors.
Failure modes
- An exception inside
effect()can abort the change-detection cycle. - An effect that writes a signal it reads creates an infinite loop.
- Browser-only signal initializers cause server/client hydration mismatches.
- Storing large mutable object graphs in signals forces deep structural reads on every change, degrading rendering performance.
Conditions that would change the design
- State must cross micro-frontend boundaries.
- You need time-travel debugging.
- You integrate heavily with non-Angular libraries.
In those cases, evaluate NgRx, an RxJS store, or a plain state container instead of forcing signals to own cross-application state.
Limitations
Signals are not a drop-in replacement for RxJS. Complex async orchestration still benefits from observables, and mixing both without clear boundaries causes synchronization bugs. Avoid deep mutable object graphs in signals; prefer small, immutable values.
Practical check: update a signal in a unit test and assert that derived signals and templates reflect the new value synchronously. If the assertion passes without manual change detection, the signal boundary is behaving as intended.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.