Bird
0
0

How can you ensure a deeply nested object input triggers change detection in an OnPush component?

hard🚀 Application Q9 of 15
Angular - Change Detection
How can you ensure a deeply nested object input triggers change detection in an OnPush component?
ACreate a new object reference when updating nested properties.
BModify nested properties directly without changing the object.
CUse <code>ChangeDetectorRef.detach()</code> to force detection.
DSet the component's change detection to default.
Step-by-Step Solution
Solution:
  1. Step 1: Recognize OnPush input detection

    OnPush detects changes by comparing input references, not deep properties.
  2. Step 2: Update nested objects correctly

    Creating a new object reference triggers detection; direct mutation does not.
  3. Final Answer:

    Create a new object reference when updating nested properties. -> Option A
  4. Quick Check:

    Trigger OnPush with new object reference [OK]
Quick Trick: Always replace objects to trigger OnPush detection [OK]
Common Mistakes:
MISTAKES
  • Mutating nested properties directly
  • Using detach() incorrectly
  • Switching to default detection unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes