Angular - Change DetectionGiven a component with OnPush strategy, what triggers change detection for it?AAny event in the app triggers itBOnly when a service updates dataCOnly when @Input properties change or an event inside the componentDChange detection never runs automaticallyCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand OnPush triggersOnPush runs change detection only when inputs change or events inside the component occur.Step 2: Eliminate incorrect triggersIt does not run on any app event or only service updates; it runs automatically on input changes or internal events.Final Answer:Only when @Input properties change or an event inside the component -> Option CQuick Check:OnPush triggers = Input changes or internal events [OK]Quick Trick: OnPush triggers on input changes or internal events [OK]Common Mistakes:MISTAKESAssuming all app events trigger OnPushThinking service updates always trigger itBelieving it never runs automatically
Master "Change Detection" in Angular9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More Angular Quizzes Angular Change Detection - Zone.js and automatic detection - Quiz 1easy Angular Change Detection - When to use OnPush - Quiz 5medium HTTP Client - Setting headers and params - Quiz 12easy Reactive Forms - Custom validators - Quiz 7medium Routing - Query parameters and fragments - Quiz 3easy RxJS Operators - debounceTime for input throttling - Quiz 6medium RxJS and Observables Fundamentals - Why observables matter in Angular - Quiz 5medium Services and Dependency Injection - Service-to-service injection - Quiz 7medium Services and Dependency Injection - How dependency injection works in Angular - Quiz 11easy Template-Driven Forms - Form validation with template attributes - Quiz 13medium