基于字符计数的角度条件类

时间:2015-08-09 20:06:45

标签: angularjs ng-class charactercount

如何根据模型的字符数有条件地应用类?

E.g:

$scope.sample = 555;

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

2 个答案:

答案 0 :(得分:1)

您可以将示例转换为字符串并检查其长度:

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

答案 1 :(得分:0)

<span ng-class="(sample.length === 3) ? 'three':'notthree'">{{ sample }}</span>