01Default change detection checks everything
Change detection is how Angular keeps the screen in sync with your data. After something happens, it walks the component tree, re-evaluates the template bindings, and updates the DOM wherever a value changed. The strategy decides which components it bothers to visit.
With the eager strategy (Angular's default until version 22), any event anywhere (a click, a timer, an HTTP response) can trigger a check of the whole component tree. On a dashboard with large tables, charts and many bindings, that cost becomes visible as input lag.
OnPush tells Angular a component only needs checking when its inputs change by reference, an event fires inside it, something marks it for check (the async pipe does this for you), or a signal it reads changes. Most enterprise components already behave that way; OnPush just lets Angular rely on it.
Angular 22 made this the framework default. A component without a changeDetection setting is now OnPush, and the old Default strategy is deprecated and renamed Eager. Zoneless change detection has been the default since Angular 21. None of that makes an existing codebase OnPush-safe, though. Most enterprise apps were written long before either change, and the work below is what turns the new defaults from a risk into a speed-up.
02Adopting it without breaking things
-
01
Make it the default for new code
On Angular 22 the framework already does this. On 21 and earlier, set the component schematic default to OnPush in
angular.json. Every new component starts correct, and the problem stops growing. -
02
Treat every
Eageras a to-doThe Angular 22 release ships a migration that adds
ChangeDetectionStrategy.Eagerwhere applicable, so upgraded components keep their old behaviour. Each one left behind is a component still to convert. Search for it and work through the list. -
03
Convert leaf components first
Presentational components with only inputs are safe to switch. Work upward from the leaves toward route components.
-
04
Stop mutating inputs
OnPush compares references (Angular uses
Object.is).items.push(x)won't update the view;items = [...items, x]will. Immutable updates are the main habit change. -
05
Signals make OnPush effortless
A signal read in a template marks that component for check when it changes, and only the components reading it are refreshed. No
markForCheck, noasyncpipe gymnastics. -
06
Watch third-party callbacks
Code that changes state from a library callback outside Angular's knowledge may not refresh the view. Writing to a signal fixes it.
-
07
Measure with the profiler
Angular DevTools' profiler shows how long each change detection cycle took and which components it checked. Its "Change detection" option greys out OnPush components that didn't re-render. Measure before and after on your heaviest screen.
03The road to zoneless
Zoneless Angular drops Zone.js and relies on explicit notifications: signals, template events, the async pipe and markForCheck. An app that is fully OnPush and signal-driven is already working that way, so going zoneless becomes a small, testable step rather than a migration.
The benefits are a smaller bundle, cleaner stack traces and no more patching of browser APIs. But the preparation is the same work as OnPush, which is why I treat "OnPush everywhere" as the first milestone of any performance roadmap.
Zoneless is the default from Angular 21, but an app that has been upgraded rather than created on 21 may still be running on Zone.js. Look for provideZoneChangeDetection() in your app config: if it's there, Zone.js is still in charge. Before removing it, check the places where zoneless behaves differently:
NgZone.onStable,onMicrotaskEmptyandonUnstablenever emit in a zoneless app. Code that waits on them (resizing a chart, measuring a layout) should move toafterNextRenderorafterEveryRender.- Reactive form value changes don't schedule change detection on their own. If a component shows something derived from a form value, read it through a signal or call
markForCheck(). - With server-side rendering, Angular needs to know when the page is done loading. Router navigation and
HttpClientrequests are tracked for you; any other async work should be wrapped withPendingTasks. - TestBed already runs zoneless by default, and it throws
ExpressionChangedAfterItHasBeenCheckedErrorfor components that aren't OnPush-compatible. A green test suite is a good early signal, andawait fixture.whenStable()is preferred overfixture.detectChanges().
NgZone.run and runOutsideAngular calls can stay; they don't need to be removed for zoneless to work.
04Defaults and the zoneless switch
Two small pieces of configuration: generate OnPush components by default, and, once the app is OnPush and signal-driven throughout, turn on zoneless change detection. What you need depends on your version.
// angular.json → projects.app.schematics
// (only needed on Angular 21 and earlier; OnPush is the default from 22)
"@schematics/angular:component": {
"changeDetection": "OnPush",
"style": "scss"
}
// app.config.ts on Angular 20: opt in explicitly
export const appConfig: ApplicationConfig = {
providers: [
provideZonelessChangeDetection(),
provideRouter(routes),
provideHttpClient(),
],
};
// Angular 21+: zoneless is the default, so the provider is optional.
// Make sure provideZoneChangeDetection() isn't overriding it, then
// remove "zone.js" and "zone.js/testing" from the polyfills in
// angular.json and run: npm uninstall zone.js
The most common code change is replacing a wait on onStable. Here a chart used to draw once Zone.js reported the app as stable. In a zoneless app that event never fires, so the chart would never draw:
import { Component, ElementRef, afterNextRender, viewChild } from '@angular/core';
@Component({
selector: 'app-revenue-chart',
template: `<canvas #canvas></canvas>`,
})
export class RevenueChartComponent {
private canvas = viewChild.required<ElementRef<HTMLCanvasElement>>('canvas');
constructor() {
// before: this.zone.onStable.pipe(take(1)).subscribe(() => this.draw());
// onStable never emits without Zone.js; this runs after the next render
afterNextRender(() => this.draw());
}
private draw() {
const ctx = this.canvas().nativeElement.getContext('2d');
// ...draw the chart with ctx
}
}
afterNextRender has to be called in an injection context, which is why it sits in the constructor. It also only runs in the browser, so the chart code is safe during server-side rendering.
The takeaway
Make OnPush the default for new components, convert existing ones from the leaves up, update state immutably or through signals, and measure. On Angular 22, every Eager left in the codebase is the remaining work. You'll get a faster app now, and a zoneless-ready one when you want it.
Sources
- Skipping component subtrees (when an OnPush component is checked; OnPush default since v22)
- ChangeDetectionStrategy API (
OnPush,Eager, deprecatedDefault) - Angular changelog, 22.0.0 (OnPush default breaking change and the
Eagermigration) - Angular without ZoneJS (zoneless) (default since v21, NgZone events, forms, SSR, testing, removing Zone.js)
- provideZonelessChangeDetection API (stable since v20.2)
- Angular DevTools profiler