Angular

Change Detection

Zone.js, change detection strategies, OnPush strategy, ChangeDetectorRef, markForCheck, detectChanges, performance optimization

20 preguntas de entrevista·
Mid-Level
1

What is the change detection mechanism in Angular?

Respuesta

Change detection is the process by which Angular detects changes in application state and updates the DOM accordingly. By default, Angular uses Zone.js to automatically detect asynchronous events (clicks, HTTP requests, timers) and triggers component checking from the root. This check traverses the component tree to identify modifications to apply to the DOM.

2

What is the role of Zone.js in Angular change detection?

Respuesta

Zone.js is a library that patches native browser asynchronous APIs (setTimeout, Promise, addEventListener, etc.) to intercept their execution. When an asynchronous operation completes, Zone.js notifies Angular which automatically triggers change detection from the root component. This allows Angular to detect changes without manual developer intervention.

3

What is the difference between Default and OnPush strategies?

Respuesta

The Default strategy checks all components in the tree on every change detection cycle, which can be expensive. OnPush optimizes by only checking a component if its inputs change (immutable references), if an event is emitted from its template, if an async pipe receives a new value, or if markForCheck() is called manually. OnPush drastically reduces checks and improves performance.

4

How to enable the OnPush strategy on a component?

5

What is the purpose of ChangeDetectorRef in an Angular component?

+17 preguntas de entrevista

Domina Angular para tu próxima entrevista

Accede a todas las preguntas, flashcards, tests técnicos, ejercicios de code review y simuladores de entrevista.

Empieza gratis