Angular 条件 Class 基于字符数

Angular Conditional Class Based On Character Count

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

例如:

$scope.sample = 555;

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

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

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