2HAASStart a project
All posts

Tech News

Angular Signals: fine-grained reactivity explained

Signals give Angular a precise way to track state: when a value changes, only the views that read it update. How signal, computed and effect work, with examples.

The 2HAAS team2 min read

For most of its life, Angular found out what to update by checking. After a click, a timer or an HTTP response, Zone.js told the framework that something might have changed, and Angular walked the component tree to compare values. It works, but it does more work than necessary, and the reason a view updated is not always obvious.

Signals replace checking with knowing. They arrived in Angular 16 and became stable in Angular 17. Each release since has moved more of the framework onto them.

The three building blocks

import { Component, computed, effect, signal } from "@angular/core";

@Component({
  selector: "app-cart",
  template: `
    <p>{{ count() }} items, total {{ total() }}</p>
    <button (click)="add(250)">Add item</button>
  `,
})
export class CartComponent {
  readonly prices = signal<number[]>([]);
  readonly count = computed(() => this.prices().length);
  readonly total = computed(() => this.prices().reduce((sum, price) => sum + price, 0));

  constructor() {
    effect(() => console.log(`The cart now holds ${this.count()} items`));
  }

  add(price: number) {
    this.prices.update((list) => [...list, price]);
  }
}
API What it is How you use it
signal() A value that can change Read with prices(), write with set() or update()
computed() A value derived from other signals Recalculated only when its inputs change, and cached
effect() Code that runs when signals change For side effects such as logging or saving

Reading a signal is a function call. That call is how Angular records which template or computation depends on which value.

Why it is faster

Because dependencies are tracked, Angular knows exactly which views read total. When prices changes, it updates those views and leaves the rest alone. No tree walk and no guessing.

This also makes Zone.js unnecessary. Recent Angular versions can run without it, which removes a dependency from the bundle and makes stack traces easier to read.

Signals and RxJS

Signals do not replace RxJS. They do different jobs:

  • Signals hold state: the current value of something.
  • Observables model events over time: key presses, WebSocket messages, a request with retries.

Angular provides bridges in @angular/core/rxjs-interop. toSignal() turns an observable into a signal for the template, and toObservable() goes the other way.

How to adopt them

  1. Start with new components. Write local state as signals from the beginning.
  2. Convert simple state next. A class field that the template reads is an easy change.
  3. Use computed for derived values. If a value can be calculated from other signals, it should not be set from an effect.
  4. Keep effects for the outside world. Logging, local storage, calls to a non-Angular library.
  5. Move inputs over. The input() function gives you component inputs as signals.

The takeaway

Signals make Angular state explicit. You can read a component and see what depends on what, and the framework uses the same information to update less. Existing applications can adopt them one component at a time, so there is no reason to wait for a rewrite.

Keep reading

  1. Tech News2 min read

    React Compiler: memoization without useMemo

    React Compiler memoizes components and values at build time, so most useMemo, useCallback and React.memo calls become unnecessary. What it does and how to adopt it.

  2. Tech News2 min read

    React 19: Actions, the use API and Server Components

    React 19 made forms and async state much simpler with Actions, useActionState and useOptimistic, added the use API and stabilized Server Components. A practical summary.

  3. Tech News2 min read

    WebGPU: modern graphics and compute in the browser

    WebGPU gives web apps direct, modern access to the graphics card for 3D rendering and for general computation such as machine learning. What it is and where it stands.

Tell us what’s in the way.

A few lines is enough. You get a candid yes, a candid no, or a sharper question.

  • Working software in week four
  • A reply in one business day
  • Handover is the deliverable

Prefer email? [email protected]

The problem, who it is for, and what is in the way right now.

One business day to a real reply. No sales sequence, no call required.