I am using angular 5 for my project. I am trying to emit event from a child component like
@Output studentUpdated:EventEmitter<any> = new EventEmitter()
updated(e){
this.studentUpdated.emit(e);
}
and listing in parent component like
<student (studentUpdated)="showSuccess($event)" />
Which work as expected. However in my student component I need to implement several events. e.g. saved, updated, deleted, confirmed, scheduled... etc
I was thinking instead of writing one event per line and calling them individually, is there a possibility that we can initialize array of events and execute them as needed. e.g.
@Output() events:EventEmitter<any>[] = []
for(var keyNum in arrayOfEvents)
{
var key = arrayOfEvents[keyNum];
this.events.push(new EventEmitter())
}
Then on certain event we emit the event based on index.
this.events[0].emit(e)
If we can then how can we do that and also how can we listen to that event on parent component ?