liveBook · Manning

Local change detection

As explained in Modern Angular

Local change detection is an Angular change-detection mode in which signal updates refresh a component without triggering checks for its OnPush ancestors.

Local change detection is Angular’s signal-aware optimization for OnPush components. When a component uses only signals, a signal update refreshes that component’s UI without triggering change detection in OnPush parent components. It relies on signals reporting their own updates, unlike ordinary component properties that Angular cannot automatically track. section 10.3.4

The mode arrived in Angular v17 after signals made reactive updates observable to Angular. It improves runtime performance by narrowing work to the component whose signal changed, while preserving incremental adoption: convert components over time rather than disrupting application logic. section 10.3.4 section 10.5

Adopt local change detection by moving toward a consistent component model:

  • Mark components with the OnPush change-detection strategy. section 10.3.4
  • Use signals exclusively within components intended to receive local updates. section 10.3.4
  • Migrate iteratively until more of the application uses OnPush and signals. section 10.3.4
  • Revisit component inputs as part of the migration, since conventional inputs are simple marked properties while signal inputs support a signal-based component model. section 10.3.4

Signal input driving project data

A project-details component can replace an @Input and ngOnChanges workflow with a required signal input. Converting that input to an observable and switching to the project request produces a signal-backed project value, aligning an input-driven component with the signals-only direction used for local change detection. section 10.3.4

id = input.required({ transform: numberAttribute });
project = toSignal(
  toObservable(this.id).pipe(
    switchMap(id => this.projectService.getProject(id))
  )
);

This implementation turns a required ID input into a signal-driven project lookup, illustrating a practical step away from ngOnChanges and ordinary input properties. section 10.3.4

Local change detection is also a step toward Angular’s zoneless direction. Signals can reduce reliance on Zone.js because they notify Angular about updates directly, although a fully zoneless future remains prospective. section 10.3.4 section 10.5

How Modern Angular covers it

How deep it goes
Explains the OnPush-and-signals condition, parent-check avoidance, performance rationale, and incremental migration without detailing engine internals.
Examples
Uses a ProjectDetailsComponent migration from @Input and ngOnChanges to an input signal and signal-backed project request.
What it assumes
Assumes familiarity with OnPush components and signals while briefly contrasting ordinary properties with signal updates.
What you can do after
Apply it by converting OnPush components to signals incrementally to reduce change-detection work.
How it connects
Connects signals, OnPush, signal inputs, Zone.js, and zoneless Angular.

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.