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

113
Views
if else condition inside for loop using angular

I am working on a task where I am looping an array inside a tag & using target="_blank" attribute but one of the array element should not want this target="_blank" attribute so what to do?

<ul *ngIf="item.menu">
            <li *ngFor="let subMenu of item.menu">
              <a href="{{subMenu.link}}" target="_blank">{{'landing.menu.' + subMenu.name | translate}}</a>
            </li>
          </ul>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can add targe attr conditionally by [attr.target]

<ul *ngIf="item.menu">
  <li *ngFor="let subMenu of item.menu">
    <a href="{{subMenu.link}}" [attr.target]="subMenu.link ? '_blank': null">{{'landing.menu.' + subMenu.name }}</a>
  </li>
</ul>

You can test here

about 4 years ago · Juan Pablo Isaza Report

0

You can use [target] around any tag property to add JS/TS code to it.

 <a href="{{subMenu.link}}" [target]="condition ? '_blank' :'other target type'">{{'landing.menu.' + subMenu.name | translate}}</a>

Other target type list: https://www.w3schools.com/tags/att_a_target.asp

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!