Angular change detection: OnPush versus default
Choosing an Angular change detection strategy—OnPush vs Default—affects how Angular decides whether a component’s bindings need to be recalculated. For many applications, Default delivers reliable behaviour with little extra work from the developer. OnPush can reduce unnecessary checks, but it changes the rules around state mutation, asynchronous updates and template rendering.
With the Default strategy, Angular can inspect a component whenever the application runs change detection. In a traditional zone-based application, browser events, timers and promises trigger those cycles. In a zoneless application, signals and explicit notifications provide the change signals instead. The strategy determines which components participate once Angular has scheduled a check.
OnPush narrows that participation. Angular skips an OnPush component unless something marks it for inspection, such as a new input reference, a component event, an emission handled by the async pipe, a signal read, or an explicit call to markForCheck(). This can improve performance, although it does not automatically make an application faster.
Australian development teams often work on products used across Sydney, Melbourne and other regional centres. A banking dashboard, supermarket loyalty application or superannuation portal may combine live account data with large collections of records. Rendering only the affected sections of such an interface is useful, provided the state updates follow patterns that OnPush understands.
How Angular’s default strategy works
In a zone-based Angular application, Zone.js patches common browser APIs so Angular can respond when asynchronous work finishes. A click, HTTP response, timeout or promise callback can therefore cause the framework to schedule a change detection cycle. The event itself may be small, but the resulting check can cover a substantial part of the component tree.
The Default strategy follows a straightforward rule: when Angular reaches a component during that cycle, it checks its template bindings regardless of whether its local values have changed. Angular compares the resulting values with the DOM and writes only genuine differences. Default child components are also checked when their parent is checked, making the behaviour easy to predict.
That predictability has a cost. A page containing many rows, charts or interpolated values creates work proportional to the size of the checked view. The framework does optimise binding checks, so Default is not inherently inefficient. It simply offers no opportunity to skip a component merely because its inputs have not changed.
What OnPush changes in the update model
OnPush introduces an identity-based contract. If a parent passes an array to a child component and later mutates that same array, the child does not receive a new input reference. Even if the array now contains different records, Angular sees the same object and has no reason to check the child.
An OnPush component participates in change detection when Angular receives a relevant notification. A changed input reference, an event bound in its own template, a new async pipe emission or a signal used by its view can all make the component eligible. Developers can also call ChangeDetectorRef.markForCheck() to mark the component and its ancestors as needing inspection.
Once an OnPush component is selected for checking, Angular can traverse its descendants according to their normal rules. A skipped OnPush component can therefore prevent work throughout that branch of the view. This is where OnPush differs from a simple toggle applied to one isolated element.
OnPush does not deep-watch objects, arrays or class instances. It also does not detect arbitrary property assignments inside an asynchronous callback. The strategy is a mechanism for controlling checks, while the application still needs a clear model for how state changes.
State updates that cooperate with OnPush
Immutable updates are the most dependable companion to OnPush. Replacing an object or array gives Angular a new reference and makes the change visible to the input system. This approach also keeps derived values predictable because each update produces a distinct state snapshot.
onToggleTask(id: number): void {
this.tasks = this.tasks.map(task =>
task.id === id ? { ...task, completed: !task.completed } : task
);
}
onRenameUser(name: string): void {
this.user = { ...this.user, name };
}
In-place mutation can still be valid in code that does not cross an OnPush boundary. For example, a component may update its own local field after one of its buttons is clicked. Angular marks the component dirty when handling the template event, so the next view update sees the changed value. The danger appears when a mutated object is shared across several components or arrives through an input binding.
Teams adopting OnPush gradually can begin with a leaf component that receives one or two inputs. Replacing direct mutations with new references there exposes unclear state flows before they spread through an application. This approach also makes component tests easier because each input change produces an observable boundary that a test can exercise.
Async work, observables, and signals
The async pipe plays an important role in OnPush components. When an observable emits a new value, the pipe updates the template and marks the component for checking. The subscription is also removed when the component is destroyed, which avoids retaining stale views.
<app-account-summary
[account]="account$ | async"
[loading]="loading$ | async">
</app-account-summary>
A manual subscription requires more care. Zone-based scheduling may cause an application tick after the callback, but an OnPush component is not necessarily dirty merely because time passed. If the callback updates ordinary fields, call markForCheck() or route the value through a signal. Using takeUntilDestroyed provides a straightforward way to stop long-lived subscriptions when the component is destroyed.
readonly account = signal<Account | null>(null);
loadAccount(): void {
this.http.get<Account>('/api/account')
.pipe(takeUntilDestroyed())
.subscribe(account => this.account.set(account));
}
Signals fit OnPush particularly well because Angular tracks the signals read by a template. Updating a signal marks its consumers as dirty, while computed signals cache derived values until their dependencies change. markForCheck() schedules future participation, whereas detectChanges() checks the view immediately. Confusing those two methods often leads developers to add unnecessary calls or chase UI that still appears stale.
Profiling and debugging change detection
The Angular DevTools profiler is the best starting point for performance work. Record a representative interaction and inspect how many components are checked, how long each check takes and which views contain the largest costs. The profiler can reveal that an expensive parent causes many children to be inspected, or that a frequently changing value triggers more work than expected.
A common failure mode involves a timer that assigns a new value to an OnPush component’s property. The timer causes Angular to run a cycle, but the component remains clean because the assignment was not connected to a template event, signal or async pipe emission. The value in memory is current while the screen remains unchanged. Enabling signal-based state or marking the component for inspection restores the expected behaviour.
Browser and unit tests can expose the same issue. A test that changes a field and calls fixture.detectChanges() may still miss an OnPush child whose input was mutated without changing its reference. Testing through component inputs and immutable state keeps the test aligned with the application’s actual contracts.
For comparison, a conventional statically generated site such as the NixMash Jekyll theme does not perform Angular’s component-tree checks. Its pages are rendered before delivery, while Angular applications create and update views in the browser. Both approaches can serve users well, but their performance models and state-update requirements are fundamentally different.
A practical strategy for Australian teams
Start with measurement rather than applying OnPush everywhere. The Default strategy remains a sensible choice for small, infrequently updated screens and for components whose inputs are expensive to compare or recreate. OnPush becomes more valuable in large views, data-heavy tables and dashboards where many stable components sit beneath a frequently changing parent.
Local usage patterns reinforce that distinction. Commuters in Sydney may check live Opal service alerts between appointments, while Melbourne passengers rely on Myki and real-time tram or train information. Interfaces supporting those journeys need current data without rebuilding every card whenever a countdown changes.
Australian financial, health and retail products also operate under market and regulatory expectations that favour explicit data handling. For many organisations, the Privacy Act 1988 and Australian Privacy Principles shape how customer information is collected and displayed. A change detection strategy does not provide privacy, but clear state boundaries and traceable updates can prevent one customer’s data from appearing in another part of a view.
Reviewing the Default strategy:
- Profile a real interaction before estimating the cost of template checks.
- Keep Default where the component is small, stable and simple to reason about.
- Measure components with large lists, charts or frequent parent updates first.
- Record which shared objects can be mutated without triggering a child update.
- Treat immutable references as part of the component’s public contract.
Adopting OnPush incrementally:
- Start with a leaf component that has a small, well-defined input surface.
- Replace array mutations and object edits with reference-changing updates.
- Prefer the async pipe or signals for data arriving outside template events.
- Use
markForCheck()for legitimate asynchronous updates that remain outside those paths. - Compare profiler results and test behaviour after each migration step.
A mixed strategy is entirely normal. A shell component may use Default to remain responsive to broad application state, while rows, panels and charts use OnPush to avoid checking unchanged content. The important requirement is that every component has a documented path by which fresh data reaches its template.
Profile one representative screen today, select a single OnPush candidate, and compare its behaviour before and after the change. Repeating that measured process will give your team a practical guideline based on your own application rather than a universal rule that ignores component size, data shape or user behaviour.