Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

219
Views
Is it a bad practice to add HostListener to target the clicks on the document, and then check if the class matches?

Is this code considered as a bad practice:

   @HostListener('document:click', ['$event'])
      clickout(event: any) {
        if (event.target.classList.contains("my-class"))
    {
    //do somthing
    }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!