Add Dynamic class in Angular 8



We can add dynamic class in Angular using NgClass .It is simple to use in HTML side lets see how

We have three class in the css with different colour


  .pending{

Color:orange;

  }

  .approved{

color:green;

  }

  .disapproved{

color:red;

  }



Above three  class  pending approved and disapproved will be used dynamically in NgClass with conditions




<div [ngClass]="{
                  'pending': element.Status =='Pending',
                  'approved': element.Status =='Approved',
                  'disapproved': element.Status =='Disapproved'
           
                  }">{{element.Status}}</div>



According to the Status the will be dynamically applied.

No comments:

Post a Comment