Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda