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

144
Views
Angular target.getAttribute () verifica la condición nula

Estaba teniendo un problema con Angular. Estoy tratando de establecer un valor diferente en consecuencia. A continuación como mi código:

 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);

Lo que estoy tratando de hacer es verificar timindId desde getAttribute (), si no es nulo, luego configúrelo. Si es nulo, getAttribute() de otro campo y luego configúrelo. Mi consola según lo siguiente:

 JJJJJJJ null KKKKKKKKK 1 INSIDE ORI SET HAHAHAHAHAHAH null

No estoy seguro de por qué cuando se detecta como nulo, no entrará en la declaración else y establecerá el valor. ¿Algunas ideas?

EDITADO

 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);

¡Gracias!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe buscar "null" como una cadena en la instrucción if .

 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 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!