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

Report an error in this question