liveBook · Manning

WritableSignal<T>

As explained in Modern Angular

A writable signal is an Angular signal whose stored value can be changed directly through its write operations.

A WritableSignal<T> is an Angular signal whose stored value can be changed through writable operations. Read its current value by invoking it as a function, such as count(). The generic type describes the stored value, and TypeScript often infers it from the initial value. section 6.2.1

import { signal } from '@angular/core';
const count = signal(0);

A minimal signal declaration shows how an initial value creates a writable signal. section 6.2.1

Use WritableSignal<T> with these boundaries in mind:

  • Provide the generic type when inference is ambiguous, such as signal<string[]>([]) for an empty string array. section 6.2.1
  • Distinguish writable signals from Signal values: computed signals and signals created from observables are read-only because their values depend on other sources. section 6.2.1 section 6.6.1
  • Expose a private writable signal as readonly when a service should control updates while consumers can only read its value. section 7.1.4

Filtering time-off requests

A time-off management component keeps selectedType as a writable signal, then derives filteredRequests and resolvedRequests with computed signals. The selection can be changed directly, while request data remains owned by its observable source. section 6.6.1

@Injectable({providedIn: 'root'})
export class SomeService {
  readonly #data = signal<Data>({});
  readonly data = this.#data.asReadonly();
}

A service pattern keeps mutation private and publishes a readonly view of the same signal. section 7.1.4

How Modern Angular covers it

How deep it goes
Explains typing, invocation, mutability boundaries, and readonly exposure, but does not detail every write operation's implementation.
Examples
Uses numeric and string-array signals, private service state, and a time-off request filter.
What it assumes
Assumes familiarity with TypeScript generics, Angular services, computed signals, and observables.
What you can do after
Evaluate and apply WritableSignal<T> by typing state, reading it through invocation, and controlling consumer access with asReadonly().
How it connects
Connects WritableSignal<T> to Signal, computed signals, observables, toSignal, and dependency injection.

Also explained in

Compare how 2 books explain WritableSignal<T> →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern Angular. The section links point to the parts of the book it draws on.