What is EventEmitter?
EventEmitter in Angular is a class used to create events in components so that a child component can send data to the parent through @Output().
How it works:
- An instance of
EventEmitteris created in the child component. - The
.emit(value)method sends data or a notification about the event. - The parent component subscribes to this event through
(eventName)and receives the passed data.
Example:
typescript
@Output() clicked = new EventEmitter<string>();
someMethod() {
this.clicked.emit('Data sent to the parent');
}Conclusion:
EventEmitteris a mechanism for communication from a child component to its parent, implementing the passing of events and data.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.