I tried with the following child component class
@Component({
selector: 'child',
templateUrl: './child.component.html'
})
export class Child implements OnInit {
@Output() send: EventEmitter<string>;
public constructor(){}
public ngOnInit() {
send = new EventEmitter<string>();
}
public onEventXYZ() {
this.send.emit('hello');
}
}
and in the parent template i am referencing the above component as
<child (send)="handleSend($event)"></child>
it resulted in this error: Cannot read property 'subscribe' of undefined...
on page load. When i later, on a friend's suggestion, moved the EventEmitter initialization from ngOnInit to the constructor, everything worked fine.
So, it too late to initialize component vars inside ngOnInit ?