Bird
0
0

Identify the error in this dynamic component loading code:

medium📝 Debug Q6 of 15
Angular - Advanced Patterns
Identify the error in this dynamic component loading code:
const componentRef = viewContainerRef.createComponent(MyComponent);
componentRef.instance.data = someData;
// Missing detectChanges call
AThe component's view will not update to show 'data' changes.
BThe component will not be created at all.
CThe code will throw a compile-time error.
DThe component will duplicate in the DOM.
Step-by-Step Solution
Solution:
  1. Step 1: Check what happens after setting inputs

    Setting 'data' on instance updates the property but does not update the view automatically.
  2. Step 2: Understand missing detectChanges effect

    Without calling detectChanges(), Angular does not refresh the view to reflect new data.
  3. Final Answer:

    The component's view will not update to show 'data' changes. -> Option A
  4. Quick Check:

    Missing detectChanges = view not updated [OK]
Quick Trick: Call detectChanges() after input changes to update view [OK]
Common Mistakes:
  • Assuming component won't create without detectChanges
  • Expecting compile-time error for missing detectChanges
  • Thinking DOM duplicates without explicit insertion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes