2

How to conditionally apply a class based on the character count of the model?

E.g.:

$scope.sample = 555;

<span ng-class="{ 'char3': sample.length == 3 }">{{ sample }}</span>

Steve
  • 4,946
  • 12
  • 45
  • 62

2 Answers2

2

You can convert sample to string and the check its length:

<span ng-class="{ char3: (sample + '').length == 3 }">{{ sample }}</span>
dfsq
  • 191,768
  • 25
  • 236
  • 258
0
<span ng-class="(sample.length === 3) ? 'three':'notthree'">{{ sample }}</span>
Liam
  • 2,837
  • 23
  • 36