When should you use the OnPush change detection strategy?
Assesses fundamental understanding of Angular conventions, runtime behavior, and memory/performance considerations.
Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.
With the default strategy Angular checks a component on every change-detection run triggered by any event, timer or XHR inside the zone. ChangeDetectionStrategy.OnPush tells Angular to skip the component unless one of its inputs changes by reference, an event originates from the component or its children, an observable bound with the async pipe emits, or you call markForCheck. This dramatically reduces checks in large apps because whole subtrees can be skipped.
@Component({ changeDetection: ChangeDetectionStrategy.OnPush })
Pitfalls: mutating an object in place does not change its reference, so OnPush inputs will not update; create a new array or object instead, or use signals. Async work outside Angular's zone, such as a custom WebSocket callback, will not trigger detection, so call markForCheck or run inside NgZone.run.
OnPush pairs well with immutable data, the async pipe and signals, and it is the default expectation for high-performance Angular components.
Candidate Response Strategy & Interview Tips
- Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
- Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
- Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
- Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.