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

97
Views
Hide/show an element by using HTML attribute as condition in Angular

I have one ng-template that is being reused as table headers.

<ng-template
  let-table="table"
  let-column="column"
  let-label="label"
  #tableHeaderTemplate
>
  <th [appSort]="table" sort-order="" [attr.sort-key]="column">
    <div>
      <span>{{ label }}</span>
      <span> (asc) </span>
      <span> (desc) </span>
    </div>
  </th>
</ng-template>

On clicking of the column header the table's data is sorted. I need to show (asc) or (desc) besides the column based on the attribute sort-order.

Check sample of my code below :

https://stackblitz.com/edit/angular-ivy-ijcuy3?file=src%2Fapp%2Fapp.component.html

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

0

You can use [hidden] attribute to hide your element and get value of sort-key attr by specifying an Identifier to your table header.

  <th #tableHeader [appSort]="table" sort-order="" [attr.sort-key]="column">
    <div>
      <span>{{ label }}</span>
      <span [hidden]="tableHeader.getAttribute('sort-order') !== 'asc'"> (asc) </span>
      <span [hidden]="tableHeader.getAttribute('sort-order') !== 'desc'"> (desc) </span>
    </div>
  </th>
</ng-template>
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!