I wrote a directive which is adding a HostListener (in this case "focus") on any component. The directive should call a method on it's host component whenever the element is on focus.
<my-component myDirective>
<h3>Hello World</h3>
</my-component>
<my-other-component myDirective>
<button>Hello</button>
</my-other-component>
The HostListener inside myDirective
@HostListener('focus')
onFocus() {
this.myService.myStream$
.pipe(first())
.subscribe((value => {
this.myHostComponent.doSomeMagic(value);
}))
}
Since it should work on every component i prefer to only implement the doSomeMagic() method in the components and letting the myDirective doing the work with the HostListener and the observable.
Is there a way to call a method on the directives host without knowing which component it actualy is?