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

147
Vistas
Angular target.getAttribute() check null condition

I was having some problem with Angular. I am trying to set different value accordingly. Below as my code:

 console.log("JJJJJJJ " + target.getAttribute("timingId"));
        console.log("KKKKKKKKK " + target.getAttribute("index"));
        if(target.getAttribute("timingId") != null){
          console.log("INSIDE ORI SET");
          this.timingId = target.getAttribute("timingId");
        } else {
          console.log("INSIDE INDEX SET");
          this.timingId = target.getAttribute("index");
        }
        console.log("HAHAHAHAHAHAH " + this.timingId);

What I am trying to do is check in timindId from getAttribute(), if it is not null, then set it. If it is null, getAttribute() from another field then set it. My console as per following:

JJJJJJJ null
KKKKKKKKK 1
INSIDE ORI SET
HAHAHAHAHAHAH null

I am not sure why when it is detected as null, it will not go into the else statement and set the value. Any ideas?

EDITED

console.log(typeof target.getAttribute("timingId"));
        console.log("JJJJJJJ " + target.getAttribute("timingId"));
        console.log("KKKKKKKKK " + target.getAttribute("index"));
        if(target.getAttribute("timingId") != null || target.getAttribute("timingId") != "null"){
          console.log("INSIDE ORI SET");
          this.timingId = target.getAttribute("timingId");
        } else {
          console.log("INSIDE INDEX SET");
          this.timingId = target.getAttribute("index");
        }
        console.log("HAHAHAHAHAHAH " + this.timingId);

Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You should check for "null" as a string in the if statement.

const timingId = target.getAttribute("timingId")
if (timingId != null && timingId !== "null") {
   this.timingId = timingId
} else {
   this.timingId = target.getAttribute("index");
}
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