I wonder when should use ngClass instead class I noticed that this style in css file
.someClass {
color: red;
}
<div [ngClass]="['someClass']">Some text</div>
<div class="someClass">Some text2</div>
working properly for two div with diff aproach. I write that when we use condition is good practice using [ngClass]. Why else? What are the benefits using [ngClass] instead class ?
using ngClass we can use expressing for class, for example, if you want to use a condition based class then need to use ng-class
<button ng-class="row.bstatus?'btn red btn-outline':'btn green-haze btn-outline'">{{row.bstatus?'Deactivate':'Activate' }}</button>
Not much benefit using it to put the single literal class name. The benefit would be to use it to dynamically set the class.
Read more here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With