Bird
0
0

What is wrong with this smart component template?

medium📝 Debug Q7 of 15
Angular - Advanced Patterns
What is wrong with this smart component template?
<app-dumb [data]="items" (update)="handleUpdate($event)"></app-dumb>

And dumb component code:
@Input() data: string[];
@Output() update = new EventEmitter();

updateData() {
  this.data.push('new');
  this.update.emit(this.data);
}
AThe smart component must not bind to update event.
BEventEmitter cannot emit arrays.
CMutating input array directly can cause unexpected side effects.
DThe dumb component should not have any outputs.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze input mutation

    The dumb component modifies the input array directly, which can affect the smart component's data unexpectedly.
  2. Step 2: Check other options

    EventEmitter can emit arrays, dumb components can have outputs, and smart components can bind to outputs.
  3. Final Answer:

    Mutating input array directly can cause unexpected side effects. -> Option C
  4. Quick Check:

    Never mutate inputs directly in dumb components [OK]
Quick Trick: Clone inputs before modifying in dumb components [OK]
Common Mistakes:
  • Assuming EventEmitter can't emit arrays
  • Believing dumb components can't emit events
  • Thinking smart components can't listen to outputs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes