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

142
Views
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 answers
Answer question

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