0

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 ?

nircraft
  • 8,242
  • 5
  • 30
  • 46
Renjus
  • 242
  • 1
  • 3
  • 15
  • Possible duplicate of [Multiple conditions in ngClass - Angular 4](https://stackoverflow.com/questions/44821875/multiple-conditions-in-ngclass-angular-4) – nircraft Feb 22 '19 at 16:27

1 Answers1

1

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>