ng class vs class binding difference in angular ?

Anil Kumar
Jun 4, 2023

--

Photo by Possessed Photography on Unsplash

Some when we work both seems to be same but there is difference we will see with example with implementation code.

Component

1. Style — scss

 .value {
background-color: yellow;
}
.integer {
color: green;
}
.number{
border: 2px solid black;
}

2. template — html

  <div class="value" [class]="['integer number']">
Label Class 10.5
</div>

<div class="value" [ngClass]="['integer number']">
Label ng class 10.5
</div>

so class will work with array of classes but ngClass works

but if we change

<div class="value" [class]="['integer', 'number']">
Label Class 10.5
</div>
<div class="value" [ngClass]="['integer number']">
Label ng class 10.5
</div>

it apply.

…..

So till now found this syntax difference. more still add…soon

--

--