Hi I have a child component with the following @input:
@Input() inputEvents: EventEmitter<{ type: string, data: string | DateModel }>;
this.inputEvents.subscribe((e: any) => {
if (e.type === 'action') {
if (e.data === 'toggle') {
this.toggle();
}
if (e.data === 'close') {
this.close();
}
if (e.data === 'open') {
this.open();
}
}
}
How do I trigger the subscribe from the parent? I have tried the following in the parent component but it does not work:
@Output() datePickerAction: EventEmitter<{ type: string, data: string }>;
this.datePickerAction.next({ type: 'action', data: 'toggle' });
Angular suggests to use the
ngOnChange()
event for that:https://angular.io/docs/ts/latest/guide/lifecycle-hooks.html#!#onchanges
So in your case, you could just "subscribe", like this: