Is this code considered as a bad practice:
@HostListener('document:click', ['$event'])
clickout(event: any) {
if (event.target.classList.contains("my-class"))
{
//do somthing
}
Well, yes - kind of. I mean if you could attach (click) listener directly on the target then you would only have to listen clicks on those targets, no need for additional queries either. Right now your listening to every click and then on top of that, querying classes on whatever target that click happens to land on - highly resource intensive way compared to attaching the listener on the right target in the first place.
<div class="my-class" (click)="onClick()"></div>
onClick() {
// do something
}