<分区>
<div ng-class:"{{myclass}}" role="progressbar" aria-valuenow="{{roundedtotalPerformanceCount}}"
aria-valuemin="0" aria-valuemax="100" ng-style="{'width' : ( totalPerformanceCount + '%' ) }">
{{roundedtotalPerformanceCount}} %
</div>
我的 Controller 代码是
if ($scope.roundedtotalPerformanceCount <= 20)
{
$scope.myclass='progress-bar-below20';
}
else
{
$scope.myclass = 'progress-bar';
}
最佳答案
以这种方式更改您的 ng-class,您可以将表达式放入:
ng-class="{'progress-bar-below20': roundedtotalPerformanceCount <= 20, 'progress-bar': roundedtotalPerformanceCount > 20}"
你也有错别字。有 :
,应该是=
这是错误的:
<div ng-class:"{{myclass}}"
应该是:
<div ng-class="myclass"
为了提高可读性,我的建议是将带有检查表达式的函数放入其中:
ng-class="{'progress-bar-below20': checkRoundedtotalPerformanceCount(), 'progress-bar': !checkRoundedtotalPerformanceCount()}"
或者如果你喜欢使用三元运算符:
ng-class="checkRoundedtotalPerformanceCount() ? 'progress-bar-below20': 'progress-bar'"
关于javascript - 如何修复类名而不是 ng 类名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44156847/
相关文章:
javascript - 有人可以解释一下这段代码是由什么组成的吗?
javascript - 拖放 Javascript if 语句问题
angularjs - Angular.module 默认名称
javascript - AngularJS - 为什么不替换 : true work with templateUrl property?
angularjs - 用于放置/删除的 CORS Cakephp 3.0 预检失败
javascript - 如果数组的连续元素重复,则通过保留该值的一个实例来仅过滤掉该数组
javascript - 如何有条件地在数组中添加或删除元素