Search code examples
angularng-class

Above or below number with ngclass Angular


I'm studying Angular. I'm training to change class if my variable is above ou below 0. It's possible to do something lile this ?

<li [ngClass]="{'list-group-item': true,
  'list-group-item-danger': loveIts < 0,
  'list-group-item-success': loveIts > 0}">

  <h4>{{postTitle}} -- {{postCreated_at | date:'dd/MM/yyyy à hh:mm' | uppercase}}</h4>


</li>

If not, what is the good way ?


Solution

  • yes is ok but you can also do in this way:

    <li class="list-group-item" [ngClass]="{
      'list-group-item-danger': loveIts < 0,
      'list-group-item-success': loveIts > 0}">
    
    <h4>{{postTitle}} -- {{postCreated_at | date:'dd/MM/yyyy à hh:mm' | uppercase}}</h4>