Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

102
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda