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() {}
}
Choose one answer
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.

Report an error in this question