You should check out Angular's documentations example for parent listens to child event:
You declare a class property with the @Output()
decorator and instantiate it to a new EventEmitter instance.
Example from the Angular docs
import { Component, EventEmitter, Input, Output } from '@angular/core';
@Component({
selector: 'app-voter',
template: `
<h4>{{name}}</h4>
<button (click)="vote(true)" [disabled]="didVote">Agree</button>
<button (click)="vote(false)" [disabled]="didVote">Disagree</button>
`
})
export class VoterComponent {
@Input() name: string;
@Output() voted = new EventEmitter<boolean>();
didVote = false;
vote(agreed: boolean) {
this.voted.emit(agreed);
this.didVote = true;
}
}
Remember it is good practice to always add generic typing to the EventEmitter if it emits a value.
If an event emits a boolean value you should instantiate it with @Output() eventName = new EventEmitter<boolean>();
The component above could be used in a parent component with <app-voter (voted)="handleVote($event)"></app-voter>