Bird
0
0

Identify the error in this dumb component code snippet:

medium📝 Debug Q6 of 15
Angular - Advanced Patterns
Identify the error in this dumb component code snippet:
@Output() clicked = new EventEmitter();

handleClick() {
  this.clicked.emit('clicked');
}
AhandleClick() must return a value.
BEventEmitter should specify a type parameter.
Cclicked should be an @Input, not @Output.
Demit() cannot send string values.
Step-by-Step Solution
Solution:
  1. Step 1: Check EventEmitter declaration

    EventEmitter should specify the type of data it emits, e.g., EventEmitter.
  2. Step 2: Validate other options

    emit() can send strings, clicked is correctly an @Output, and handleClick() does not need to return anything.
  3. Final Answer:

    EventEmitter should specify a type parameter. -> Option B
  4. Quick Check:

    Always type EventEmitter for clarity [OK]
Quick Trick: Type your EventEmitter to avoid errors [OK]
Common Mistakes:
  • Omitting type parameter on EventEmitter
  • Confusing @Input and @Output decorators
  • Expecting functions to always return values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes