Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda