Bird
0
0

Given this parent and child component code, what will be logged when the child emits an event?

medium📝 component behavior Q13 of 15
Angular - Component Interaction
Given this parent and child component code, what will be logged when the child emits an event?
Child component TS:
@Output() notify = new EventEmitter();
sendNotification() { this.notify.emit('Hello'); }

Parent component template:
<child-comp (notify)="onNotify($event)"></child-comp>

Parent component TS:
onNotify(message: string) { console.log(message); }
AHello
Bundefined
CError: notify is not a function
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand event emission

    The child emits 'Hello' via notify.emit('Hello').
  2. Step 2: Check parent event binding

    The parent listens with (notify)="onNotify($event)", so onNotify receives 'Hello'.
  3. Final Answer:

    Hello -> Option A
  4. Quick Check:

    Child event emits 'Hello' caught by parent [OK]
Quick Trick: Child emits event, parent listens with (event) binding [OK]
Common Mistakes:
  • Confusing @Output with @Input
  • Not passing $event in parent handler
  • Expecting no output without calling emit

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes