Bird
0
0

Consider a component with an input property items which is an array. If the parent modifies the array contents but does not replace the array reference, will ngOnChanges detect the change?

hard📝 Conceptual Q9 of 15
Angular - Lifecycle Hooks
Consider a component with an input property items which is an array. If the parent modifies the array contents but does not replace the array reference, will ngOnChanges detect the change?
AYes, but only if the array length changes
BNo, because <code>ngOnChanges</code> detects changes by reference, not by internal mutations
CYes, it detects any change inside the array automatically
DNo, because arrays are not supported as inputs
Step-by-Step Solution
Solution:
  1. Step 1: Understand how Angular detects input changes

    Angular compares input references, not deep content.

  2. Step 2: Apply to array mutation scenario

    Mutating array contents without changing reference does not trigger ngOnChanges.

  3. Final Answer:

    No, because ngOnChanges detects changes by reference, not by internal mutations -> Option B
  4. Quick Check:

    Input change detection uses reference equality [OK]
Quick Trick: Change input object reference to trigger ngOnChanges [OK]
Common Mistakes:
  • Assuming internal mutations trigger ngOnChanges
  • Thinking Angular does deep comparison automatically
  • Believing array length changes trigger detection

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes