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,435
  • 8
  • 36
  • 59

2 Answers2

2

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

<span ng-class="{ char3: (sample + '').length == 3 }">{{ sample }}</span>
dfsq
  • 182,609
  • 24
  • 222
  • 242
0
<span ng-class="(sample.length === 3) ? 'three':'notthree'">{{ sample }}</span>
Abhi
  • 2,779
  • 20
  • 36