NG.VIII · Angular 22 practice question
In an Angular app, MainComponent uses OnPush and renders LoginComponent, which also uses OnPush. When Angular handles a click event inside LoginComponent, what happens to change detection?
Check answer and explanation
Correct answer: Angular executes change detection across the entire component tree, including LoginComponent's ancestors such as MainComponent
Explanation
When Angular handles an event inside an OnPush component, it runs change detection across the entire component tree, including the component's ancestors like MainComponent.
Common trap
It is tempting to assume OnPush isolates a parent from child events, but Angular still checks ancestor components when a descendant handles an event. Believing that only input changes trigger OnPush checks ignores that handled events also schedule change detection along the component tree.
Source: Angular docs: Skipping component subtrees — An event is handled by a descendant of a component with OnPush
Checked against the cited text on 2026-11-25.