Bird
0
0

Examine this Angular child component code:

medium📝 Debug Q6 of 15
Angular - Component Interaction
Examine this Angular child component code:
import { Component, Output, EventEmitter } from '@angular/core';
@Component({ selector: 'child-comp', template: '' })
export class ChildComponent {
  @Output() clicked = new EventEmitter();
  send() {
    this.clicked.emit('data');
  }
}

What is the issue with this code?
AThe send method should not call emit directly.
BThe @Output decorator is missing parentheses.
CThe EventEmitter should not have a generic type.
DThere is no issue; the code correctly emits an event.
Step-by-Step Solution
Solution:
  1. Step 1: Check @Output syntax

    The decorator is correctly used with parentheses.
  2. Step 2: EventEmitter usage

    The EventEmitter is properly instantiated with a generic type string.
  3. Step 3: Emitting event

    The send() method correctly calls emit with a string argument.
  4. Final Answer:

    There is no issue; the code correctly emits an event. -> Option D
  5. Quick Check:

    Code follows correct @Output and EventEmitter pattern [OK]
Quick Trick: Check for @Output() and new EventEmitter() [OK]
Common Mistakes:
  • Forgetting parentheses after @Output
  • Not initializing EventEmitter
  • Calling emit before initialization

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes