Bird
0
0

You have an Angular component with OnPush strategy but the view does not update after input changes. Which fix will solve this problem?

medium📝 Debug Q14 of 15
Angular - Change Detection
You 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 mutation
BSwitch to Default change detection strategy
CReplace the input object with a new reference instead of mutating it
DRemove the <code>@Input()</code> decorator
Step-by-Step Solution
Solution:
  1. Step 1: Identify why view doesn't update

    OnPush requires new input references to detect changes; mutating inputs keeps the same reference, so no update.
  2. Step 2: Choose the best fix

    Replacing the input with a new object triggers change detection properly without needing manual calls or strategy changes.
  3. Final Answer:

    Replace the input object with a new reference instead of mutating it -> Option C
  4. Quick Check:

    New input references trigger OnPush updates = C [OK]
Quick Trick: Use new input objects, not mutations, to update OnPush views [OK]
Common Mistakes:
MISTAKES
  • Relying on manual detectChanges() calls unnecessarily
  • Switching to Default without reason
  • Removing @Input() breaks data flow

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes