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>

4

2 回答 2

2

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

<span ng-class="{ char3: (sample + '').length == 3 }">{{ sample }}</span>
于 2015-08-09T20:13:30.663 回答
0
<span ng-class="(sample.length === 3) ? 'three':'notthree'">{{ sample }}</span>
于 2015-08-09T20:24:17.570 回答