Skip to main content

What is the role of ChangeDetectorRef and when should it be used?

Mid Angular
Quick Answer ChangeDetectorRef gives manual control over change detection. detach() removes a component from the CD tree (must manually call detectChanges()). markForCheck() marks an OnPush component to be checked on next CD cycle (useful when data changes externally). detectChanges() synchronously runs CD on this component and its children. Use when integrating non-Angular code that changes state without triggering Zone.js.

Answer

ChangeDetectorRef gives manual control over Angular’s change detection.

Used when working with OnPush, avoiding heavy re-renders, handling updates outside Angular zones, or running performance-sensitive operations.

S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice