Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NgClass vs Class [duplicate]

Tags:

css

angular

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 ?

like image 639
Walter White Avatar asked Oct 15 '17 18:10

Walter White


2 Answers

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>

like image 80
RANVIR GORAI Avatar answered Oct 21 '22 01:10

RANVIR GORAI


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.

like image 5
ChiefTwoPencils Avatar answered Oct 21 '22 02:10

ChiefTwoPencils