← Learning Hub
Beginner

Signals

A signal holds a value that can change. When it changes, Angular updates every place that shows it. Signals are the modern, simple way to keep state in Angular 20.

Any app needs data that changes: a cart count, a selected size, a logged-in user. Angular needs to know when such data changes so it can update the page. Signals make this explicit and efficient: Angular knows exactly which parts of the page read which signal, so it updates only those parts.

computed signals are values worked out from others, like a cart total from the item list. You never update them yourself - when the items change, the total updates automatically. This removes a whole class of bugs where one value is updated and a related value is forgotten.

  • signal(0) creates a signal with a starting value.
  • Read it by calling it like a function: count().
  • Change it with .set(5) or .update(n => n + 1).
  • computed() makes a value that is worked out from other signals and updates by itself.
Example
import { Component, signal, computed } from '@angular/core';

@Component({
  selector: 'app-cart',
  template: `
    <p>Items: {{ count() }}</p>
    <p>Total: Rs {{ total() }}</p>
    <button (click)="add()">Add item</button>
    <button (click)="count.set(0)">Empty cart</button>
  `,
})
export class Cart {
  price = 499;
  count = signal(0);
  total = computed(() => this.count() * this.price);

  add() {
    this.count.update(n => n + 1);
  }
}
Remember the brackets when reading a signal in a template: {{ count() }}, not {{ count }}.
Key points
  • A signal holds a changing value; read it by calling it: count().
  • Change it with .set() or .update().
  • computed() derives values that stay in sync automatically.

📝 Test yourself

1. How do you read the value of a signal called count?
2. Which function makes a value worked out from other signals?
3. Fill in the method that changes a signal using its current value:
count.(n => n + 1);