Angular - Change DetectionYou have an Angular component with OnPush strategy but the view does not update after input changes. Which fix will solve this problem?AManually call <code>ChangeDetectorRef.detectChanges()</code> after input mutationBSwitch to Default change detection strategyCReplace the input object with a new reference instead of mutating itDRemove the <code>@Input()</code> decoratorCheck Answer
Step-by-Step SolutionSolution:Step 1: Identify why view doesn't updateOnPush requires new input references to detect changes; mutating inputs keeps the same reference, so no update.Step 2: Choose the best fixReplacing the input with a new object triggers change detection properly without needing manual calls or strategy changes.Final Answer:Replace the input object with a new reference instead of mutating it -> Option CQuick Check:New input references trigger OnPush updates = C [OK]Quick Trick: Use new input objects, not mutations, to update OnPush views [OK]Common Mistakes:MISTAKESRelying on manual detectChanges() calls unnecessarilySwitching to Default without reasonRemoving @Input() breaks data flow
Master "Change Detection" in Angular9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More Angular Quizzes Angular Change Detection - Default change detection strategy - Quiz 8hard HTTP Client - Handling HTTP errors - Quiz 15hard HTTP Client - Loading states and error patterns - Quiz 11easy Routing - RouterLink for navigation - Quiz 15hard Routing - Query parameters and fragments - Quiz 7medium RxJS Operators - combineLatest and forkJoin for combining - Quiz 4medium RxJS Operators - map operator for transformation - Quiz 9hard Services and Dependency Injection - Singleton service behavior - Quiz 5medium Services and Dependency Injection - How dependency injection works in Angular - Quiz 6medium Template-Driven Forms - Two-way binding in forms - Quiz 6medium