Assume I am working with a component:
@Component({selector: 'todo-cmp'})
class TodoCmp {
@Input() model;
@Output() complete = new EventEmitter(); // TypeScript supports initializing fields
onCompletedButton() {
this.complete.next(); // this triggers an event
}
}
Now, in another component, I am injecting a copy of this component using Dependency Injection:
...
class SomeOtherClass(){
constructor(todoCmp:TodoCmp){
// How can I listen to events from the injected ToDoCmp instance?
...
}
...
Is there a way to manually add an event listener inside "SomeOtherClass" and capture any click events triggered by the dependency-injected instance of ToDoCmp?
Perhaps something like todoCmp.addEventListener('complete', function(e){})?
Or is there a better approach in Angular 2 for achieving this?
Thanks,
Sean.