liveBook · Manning

Update method

As explained in Modern Angular

A signal update method derives and assigns a new value by applying a callback to the signal's previous value.

An Angular signal’s update method derives a replacement value from the signal’s current value. It accepts a callback, passes that callback the previous value, and stores the callback’s return value. Unlike directly calculating a value before calling set, update keeps the read-and-derive operation together. section 6.2.2 section 6.8

Use update when the next value depends on the existing signal value:

  • Increment a numeric signal with count.update(value => value + 1). section 6.2.2
  • Add an item to an array by returning a new array that spreads the previous items and appends the new value. section 6.2.2
  • Return a value matching the signal’s declared type; a numeric signal’s callback cannot return an array or another incompatible value. section 6.2.2

Approving a time-off request

A component can update an array of request objects without replacing it manually at the call site. The callback locates the request, maps the existing array, and returns a new array in which the matching item has status 'Approved'. The same pattern supports request rejection and other enterprise workflow changes. section 6.3.2

How Modern Angular covers it

How deep it goes
Defines the callback contract and demonstrates numeric, array, and object-array updates, without detailing signal internals.
Examples
Uses counter increments, appended names, and time-off request approval to demonstrate derived replacements.
What it assumes
Assumes familiarity with Angular signals, callbacks, TypeScript types, arrays, and immutable object or array transformations.
What you can do after
Apply it via Angular signals to update primitive values, append array items, or modify matching objects in component state.
How it connects
Connects signal updates with set, computed signals, RxJS interoperability, immutable array operations, and Angular components.

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.