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

239
Visualizações
Angular 2 conditional class active in second condition not working

I added code to show the sort direction as well as color for selected column see the plunker

  • if sortable show up/down arrow: working
  • if Ascending show down arrow with active color: ACTIVE NOT APPLYING
  • if descending show up arrow with active color: working

Here is the code to application class conditionally:

<i class="fa fa-lg" [ngClass]="{'fa-sort' :  column !== 'ProjectID',  
   ' fa-sort-asc active'  : (column === 'ProjectID' && !isDesc), 
   ' fa-sort-desc active' : (column === 'ProjectID' && isDesc) }" 
    aria-hidden="true"></i>

See ASC and DESC both have active class which is working only with DESC true condition, please see the plunker for more detail.

Here the code after applying all conditions:

<i aria-hidden="true" class="fa fa-lg fa-sort"></i>
<i aria-hidden="true" class="fa fa-lg fa-sort-asc"></i> // active missing
<i aria-hidden="true" class="fa fa-lg fa-sort-desc active"></i>

Any Idea why it is behaving like this:

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Conditions in ngClass are applied in order. When the condition in ngClass is evaluated to false, it removes corresponding classes. If the same class is in two conditions, it might be added at first but in the next condition, it will be removed.

Possible solutions would be:

  1. change style classes to .active-asc, .active-desc {color: red;} and then apply them respectively in the conditions;

or

  1. add new condition 'active' : column === 'columnName'
over 4 years ago · Santiago Trujillo 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