I recommend using ngClass instead of ngIf
to dynamically stylize its components. Let’s imagine a scenario where you have multiple styles, you would have to make multiple components equal by just changing their style, that’s bad practice because you’re repeating code.
Example:
<p [ngClass]="getClass()">{{resultado.mediaTotal}}</p>
Note that we are not doing any validation in html, we can leave this part pro component
, where in this example I created the function getClass()
In your Component/Page you would do something like:
getClass(){
if(this.resultado.mediaTotal > 50 && this.resultado.mediaTotal < 70)
return 'my-style-green'
if(this.resultado.mediaTotal < 50)
return 'my-style-red'
}
Note that it is returning a string, this string is your class that you can put in your page’s css.
.my-style-green{
color: green;
}
.my-style-red{
color: red;
}