有没有更简洁的方法来写这个:
ng-class="{ 'red': (percent < 0), 'green': (percent > 0), 'glyphicon-arrow-down': (percent < 0), 'glyphicon-arrow-up': (percent > 0) }"
我发现自己写了很多这些过长的ng-class
属性表达式。
答案 0 :(得分:0)
您可以组合相似条件的类别。
ng-class="{ 'red glyphicon-arrow-down': (percent < 0), 'green glyphicon-arrow-up': (percent > 0) }"
答案 1 :(得分:0)
可能会删除括号:
ng-class="{ 'red': percent < 0,
'green': percent > 0,
'glyphicon-arrow-down': percent < 0,
'glyphicon-arrow-up': percent > 0 }"