Change detection and zoneless: Angular 22 practice questions
Change detection and zoneless is 8% of the free Angular 22 mock (4 of 50 questions). Pick an answer to see right away whether it is correct, with the explanation and the documentation section it comes from.
NG.VIII · Angular 22 practice question
In an Angular app, MainComponent uses OnPush and renders LoginComponent, which also uses OnPush. When Angular handles a click event inside LoginComponent, what happens to change detection?
Check answer and explanation
Correct answer: Angular executes change detection across the entire component tree, including LoginComponent's ancestors such as MainComponent
Explanation
When Angular handles an event inside an OnPush component, it runs change detection across the entire component tree, including the component's ancestors like MainComponent.
Common trap
It is tempting to assume OnPush isolates a parent from child events, but Angular still checks ancestor components when a descendant handles an event. Believing that only input changes trigger OnPush checks ignores that handled events also schedule change detection along the component tree.
Source: Angular docs: Skipping component subtrees — An event is handled by a descendant of a component with OnPush
Checked against the cited text on 2026-11-25.
NG.VIII · Angular 22 practice question
A developer authors this standalone component in Angular 22 without setting a changeDetection property in the @Component decorator. Which change detection strategy does Angular apply?
import { Component, input } from '@angular/core';
@Component({
selector: 'app-badge',
template: `<span>{{ label() }}</span>`,
})
export class BadgeComponent {
label = input.required<string>();
}
Check answer and explanation
Correct answer: OnPush
Explanation
Starting in Angular v22, OnPush is the default change detection strategy when a component omits an explicit changeDetection setting.
Common trap
Developers used to Angular v21 and earlier often expect CheckAlways (Default) when changeDetection is omitted, but Angular v22 switched the default to OnPush. Detached is not a built-in default strategy in @Component and would prevent automatic updates unless manually reattached.
Source: Angular docs: Skipping component subtrees — Using `OnPush`
Checked against the cited text on 2026-11-25.
NG.VIII · Angular 22 practice question
During a code review of an Angular 22 test suite, a developer notices this TestBed setup. Is provideZonelessChangeDetection() required here to run the test with zoneless change detection?
TestBed.configureTestingModule({
providers: [provideZonelessChangeDetection()],
});
Check answer and explanation
Correct answer: No, because including provideZonelessChangeDetection() in TestBed is optional
Explanation
Including provideZonelessChangeDetection() in TestBed is optional because TestBed already uses zoneless change detection by default.
Common trap
Teams familiar with earlier Angular versions where zoneless had to be opted in often assume the provider is still mandatory, but Angular 22 TestBed is zoneless by default. Developers sometimes worry that fixture.whenStable() requires an explicit zoneless provider, yet TestBed works with whenStable() in zoneless mode without adding it.
Source: Angular docs: Angular without ZoneJS (Zoneless) — Using Zoneless in `TestBed`
Checked against the cited text on 2026-11-25.
NG.VIII · Angular 22 practice question
An engineering team is evaluating why removing ZoneJS improves runtime performance. Why does ZoneJS trigger application synchronization more often than needed?
Check answer and explanation
Correct answer: Because ZoneJS cannot tell whether application state actually changed when DOM events or async tasks occur
Explanation
ZoneJS relies on DOM events and async tasks as guesses that state might have changed, lacking insight into whether application state actually updated and therefore triggering synchronization too frequently.
Common trap
Assuming ZoneJS uses a 16ms polling loop confuses event-driven monkey-patching with frame-based polling; ZoneJS reacts to DOM events and async tasks instead. ZoneJS does not disable OnPush, though it still triggers application-level synchronization cycles whenever patched async tasks complete.
Source: Angular docs: Angular without ZoneJS (Zoneless) — Why use Zoneless?
Checked against the cited text on 2026-11-25.
NG.VIII · Angular 22 practice question
A library service is used inside an Angular 22 zoneless application. When watch() runs in the snippet below, why is this.measure() never called?
import { Injectable, NgZone, inject } from '@angular/core';
@Injectable({ providedIn: 'root' })
export class MeasureService {
private ngZone = inject(NgZone);
watch() {
this.ngZone.onStable.subscribe(() => this.measure());
}
private measure() {}
}
Check answer and explanation
Correct answer: Because NgZone.onStable never emits when an application uses zoneless change detection
Explanation
In a zoneless application, NgZone lifecycle observables including onStable, onMicrotaskEmpty, and onUnstable never emit, so subscribers are never notified.
Common trap
Developers familiar with late-subscription bugs may assume they missed an early emission, but in zoneless mode onStable never emits at all. NgZone remains injectable in zoneless applications for compatibility, so inject(NgZone) succeeds rather than returning null.
Source: Angular docs: Angular without ZoneJS (Zoneless) — Remove `NgZone.onMicrotaskEmpty`, `NgZone.onUnstable`, `NgZone.isStable`, or `NgZone.onStable`
Checked against the cited text on 2026-11-25.
NG.VIII · Angular 22 practice question
A developer maintains a legacy spec file in Angular 22 that still depends on Zone-based change detection inside TestBed. Which provider must be registered in TestBed.configureTestingModule to enable Zone-based mode for that test?
Check answer and explanation
Correct answer: provideZoneChangeDetection()
Explanation
Registering provideZoneChangeDetection() in TestBed's providers explicitly switches the test environment to Zone-based change detection.
Common trap
provideNgZone() sounds plausible because NgZone is the core Angular service, but Angular does not provide a function with that name for configuring change detection. provideLegacyChangeDetection() sounds like a migration helper for older behavior, but the actual Angular API is provideZoneChangeDetection().
Source: Angular docs: Angular without ZoneJS (Zoneless) — Using Zoneless in `TestBed`
Checked against the cited text on 2026-11-25.
NG.VIII · Angular 22 practice question
A developer migrates a service to an Angular 22 zoneless application and keeps the following stability check. How does this.ngZone.isStable behave at runtime in zoneless mode?
import { Injectable, NgZone, inject } from '@angular/core';
@Injectable({ providedIn: 'root' })
export class InitService {
private ngZone = inject(NgZone);
runIfReady() {
if (this.ngZone.isStable) {
this.initialize();
}
}
private initialize() {}
}
Check answer and explanation
Correct answer: It always evaluates to true, making it unsuitable as a condition for gating execution
Explanation
In a zoneless application, NgZone.isStable is always true and therefore should not be relied on as a conditional guard for executing code.
Common trap
Since NgZone observables stop emitting in zoneless mode, developers often assume isStable stays false, when in fact it is always true. NgZone.isStable still exists on NgZone without throwing, which is why stale conditional checks can silently run unconditionally unless removed.
Source: Angular docs: Angular without ZoneJS (Zoneless) — Remove `NgZone.onMicrotaskEmpty`, `NgZone.onUnstable`, `NgZone.isStable`, or `NgZone.onStable`
Checked against the cited text on 2026-11-25.
NG.VIII · Angular 22 practice question
A team migrating an Angular 22 storefront to zoneless mode wants to explain the Core Web Vitals benefit to stakeholders. Which two kinds of overhead does removing ZoneJS eliminate?
Check answer and explanation
Correct answer: Payload size and startup time
Explanation
Removing ZoneJS improves Core Web Vitals because ZoneJS adds notable overhead to both payload size and application startup time.
Common trap
Layout shifts and CSS rules affect Core Web Vitals in general, but ZoneJS does not manage CSS or animations. HTTP caching and hydration scripts are unrelated to ZoneJS's runtime bundle footprint and initialization cost.
Source: Angular docs: Angular without ZoneJS (Zoneless) — Why use Zoneless?
Checked against the cited text on 2026-11-25.
NG.VIII · Angular 22 practice question
A developer needs to profile rendering bottlenecks and understand runtime performance in an Angular 22 app. Which pair of tools does the Angular runtime performance overview recommend for profiling?
Check answer and explanation
Correct answer: Angular DevTools and Chrome DevTools
Explanation
The Angular runtime performance guide highlights Angular DevTools along with Chrome DevTools for profiling application performance.
Common trap
NgZone Inspector and Karma Runner sound Angular-specific, but neither is the profiling pair recommended in the runtime performance overview. TypeScript Compiler Trace profiles build-time type checking rather than runtime rendering, and the overview specifically points to Angular DevTools and Chrome DevTools.
Source: Angular docs: Runtime performance optimization — Runtime performance optimization
Checked against the cited text on 2026-11-25.
NG.VIII · Angular 22 practice question
An OnPush subtree root contains a child component that does not use OnPush. When Angular handles a @HostListener event on that child component, what happens to change detection for the subtree?
Check answer and explanation
Correct answer: Angular runs change detection for the subtree regardless of whether the child uses OnPush
Explanation
Angular runs change detection for an OnPush subtree whenever it handles an event—such as an event binding, output binding, or @HostListener—in the subtree root or any descendant, whether or not that descendant uses OnPush.
Common trap
It is easy to think a non-OnPush child behaves differently under an OnPush root, yet handled events in any child trigger change detection for the subtree regardless of the child's strategy. Developers sometimes assume only template (event) bindings trigger OnPush, overlooking that output bindings and @HostListener events trigger it as well.
Source: Angular docs: Skipping component subtrees — Using `OnPush`
Checked against the cited text on 2026-11-25.
NG.VIII · Angular 22 practice question
A parent template passes a bound value to an input on an OnPush subtree's root component. How does Angular compare the previous and current input values to decide whether the component received a new input?
Check answer and explanation
Correct answer: Object.is comparison between the current and previous values
Explanation
Angular compares the previous and current input values using Object.is to determine whether a template binding delivered a new input to the subtree's root component.
Common trap
Deep structural comparison is expensive and would defeat OnPush's performance benefits, so Angular does not walk nested properties. Serializing with JSON.stringify fails on circular references and functions and is never used by Angular for input change checks.
Source: Angular docs: Skipping component subtrees — Using `OnPush`
Checked against the cited text on 2026-11-25.
NG.VIII · Angular 22 practice question
A developer profiles an OnPush parent component (MainComponent) and sees it getting checked whenever an event is handled inside its OnPush child (LoginComponent). Why does Angular check MainComponent as well?
Check answer and explanation
Correct answer: Because LoginComponent is part of MainComponent's view
Explanation
Angular checks MainComponent when LoginComponent handles an event because LoginComponent is part of MainComponent's view.
Common trap
Developers sometimes assume nesting components invalidates OnPush, but OnPush remains active and simply checks ancestors whose view contains the event source. Events do not mutate parent input bindings; the parent is checked because the child belongs to its view.
Source: Angular docs: Skipping component subtrees — An event is handled by a descendant of a component with OnPush
Checked against the cited text on 2026-11-25.
NG.VIII · Angular 22 practice question
A team upgrades an application to Angular 22 while still loading zone.js in polyfills. When the following unit test runs without any change-detection providers, which mode does TestBed use?
it('renders user details', async () => {
TestBed.configureTestingModule({});
const fixture = TestBed.createComponent(UserCard);
await fixture.whenStable();
});
Check answer and explanation
Correct answer: Zoneless change detection by default
Explanation
TestBed defaults to zoneless change detection in Angular 22 regardless of whether zone.js is included in the application's polyfills.
Common trap
Developers migrating older projects often assume loading zone.js in polyfills automatically enables Zone-based testing, but TestBed still defaults to zoneless mode. Manual-only detection is a common misconception about zoneless tests, whereas TestBed runs zoneless change detection automatically and settles with fixture.whenStable().
Source: Angular docs: Angular without ZoneJS (Zoneless) — Using Zoneless in `TestBed`
Checked against the cited text on 2026-11-25.
NG.VIII · Angular 22 practice question
In a Zone-based Angular application, a developer writes the following component to poll a background endpoint every 500 milliseconds. What is the effect of wrapping setInterval in this.ngZone.runOutsideAngular?
import { Component, NgZone, OnInit, inject } from '@angular/core';
@Component({ selector: 'app-poller', template: '' })
export class PollerComponent implements OnInit {
private ngZone = inject(NgZone);
ngOnInit() {
this.ngZone.runOutsideAngular(() => setInterval(() => this.poll(), 500));
}
private poll() {}
}
Check answer and explanation
Correct answer: It runs setInterval outside the Angular zone so change detection is skipped after each poll callback
Explanation
Calling setInterval inside ngZone.runOutsideAngular keeps the timer outside the Angular zone and instructs Angular to skip running change detection after the callback executes.
Common trap
The phrase 'outside Angular' can sound like off-main-thread execution, but runOutsideAngular still executes on the main JavaScript thread without creating a Web Worker. Developers sometimes confuse skipping change detection with pausing the timer, whereas setInterval continues firing every 500 milliseconds without triggering Angular checks.
Source: Angular docs: Resolving zone pollution — Run tasks outside `NgZone`
Checked against the cited text on 2026-11-25.
NG.VIII · Angular 22 practice question
In a Zone-based app, a developer initializes a third-party charting library inside ngZone.runOutsideAngular and attaches a click handler to the chart. When the user clicks the chart, why does that click handler execute outside the Angular zone?
Check answer and explanation
Correct answer: Because the chart's initialization logic was also executed outside the Angular zone
Explanation
The event callback runs outside the Angular zone because the initialization logic that registered it was also called outside the Angular zone.
Common trap
Without runOutsideAngular, Zone.js patches browser APIs so third-party listeners often do execute inside the Angular zone and cause zone pollution. NgZone.isInAngularZone() is a read-only check that reports whether code is inside the Angular zone; it does not change the active zone.
Source: Angular docs: Resolving zone pollution — Run tasks outside `NgZone`
Checked against the cited text on 2026-11-25.