Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

225
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda