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

159
Views
Adding ngIf to script tag in html not working

I am trying to add a src to a script in my html file, but only if a condition is true. Otherwise it should not have run the script src. Below is my code so far:

    <script>
      this.booleanValue = JSON.parse(
        sessionStorage.getItem("booleanValue")
      );

      if (this.booleanValue == "true") {
        console.log("true");
      }
    </script>
    <script
      *ngIf="this.booleanValue != true"
      src="code.js"
      async
    ></script>

It console logs the booleanValue as true correctly, however it still runs the script src. It shouldn't because it should only run when false. Does anyone know what I'm doing wrong?

Thanks in advance

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

0

You're JSON parsing "booleanValue" when doing :

JSON.parse(
    sessionStorage.getItem("booleanValue")
  )

And you're trying to get value of this.booleanValue directly, it'd be something like 'this.booleanValue.value' when verifying if its value is true or not, or you don't use JSON.parse().

Example: If Session variable is booleanValue => true, you use if(this.booleanValue), but if Session variable is booleanValue => "{value:true}" or "{\"value\":true}", then you use JSON.parse and if(this.booleanValue.value)

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!