Signals: signal, computed and effect

Angular 17 min min read Updated: Nov 16, 2026 Intermediate
Signals: signal, computed and effect
Intermediate Topic 4 of 7

What Is a Signal?

A signal is a box that holds a value and tells Angular when the value changes. Angular then updates only the parts of the screen that use that value.

Simple example: A spreadsheet. If cell C1 is =A1+B1, changing A1 updates C1 automatically. Signals work like this for your component data.

Writable Signals

typescript import { Component, signal } from '@angular/core'; @Component({ selector: 'app-counter', template: ` <p>Count: {{ count() }}</p> <button (click)="increment()">+1</button> <button (click)="reset()">Reset</button> `, }) export class Counter { count = signal(0); increment() { this.count.update(c => c + 1); } reset() { this.count.set(0); } }
ActionCode
Createconst count = signal(0)
Readcount() (call it like a function)
Replacecount.set(5)
Change based on old valuecount.update(c => c + 1)
Do not forget the brackets: In the template write {{ count() }}, not {{ count }}. The brackets read the current value.

computed: Derived Values

typescript export class Cart { items = signal([ { name: 'Book', price: 12, qty: 2 }, { name: 'Pen', price: 2, qty: 5 }, ]); total = computed(() => this.items().reduce((sum, i) => sum + i.price * i.qty, 0)); count = computed(() => this.items().length); isEmpty = computed(() => this.count() === 0); }

A computed signal is read-only, recalculates only when the signals it uses change and caches its result.

Update Arrays and Objects the Immutable Way

typescript addItem(item: Item) { this.items.update(list => [...list, item]); // new array } remove(name: string) { this.items.update(list => list.filter(i => i.name !== name)); } changeQty(name: string, qty: number) { this.items.update(list => list.map(i => i.name === name ? { ...i, qty } : i)); }
Never mutate: this.items().push(x) changes the array without telling Angular. Always create a new array or object with spread, map or filter.

effect: Run Code When Signals Change

typescript constructor() { effect(() => { console.log('Cart total is now', this.total()); localStorage.setItem('cart', JSON.stringify(this.items())); }); }

Use effect for side effects: logging, saving to local storage, drawing on a canvas. Do not use it to set other signals. Use computed for that.

linkedSignal: Resettable Derived State

typescript options = signal(['S', 'M', 'L']); selected = linkedSignal(() => this.options()[0]); // resets to first option when options change choose(size: string) { this.selected.set(size); } // but you can still set it

Signals vs Plain Properties vs Observables

SignalPlain propertyObservable (RxJS)
Current valueAlways (s())AlwaysNo, only when it emits
Best forComponent and UI stateConstantsStreams over time: HTTP, events, websockets
Updates viewAutomatically and preciselyNeeds change detectionWith async pipe or toSignal
typescript // read without tracking inside an effect import { untracked } from '@angular/core'; effect(() => { const a = this.a(); untracked(() => console.log(this.b())); });

Conclusion

Create state with signal, derive values with computed, run side effects with effect and always update with set or update using new objects and arrays.

Quick Summary: signal() holds state, computed() derives, effect() reacts; read with ().

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators