伍式有条件 [英] Ng-style with condition
本文介绍了伍式有条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在满足所列条件的列表中的某些项目上应用样式:
How can I apply style on some item in a list that satisfy listed condition:
<div data-ng-repeat="item in items">
<div data-ng-style="{'background' : 'red' : item.selected}> {{item.name}}
<div>
<div>
如何在所选项目上应用此样式.
How is it possible to apply this style on item that is selected.
推荐答案
我认为最好使用ng-class
解决您的问题.然后,为红色背景创建一个新类,例如:
I think it would be best to use ng-class
for your problem. You then make a new class for the red background, eg:
<style>
.red-background{
background-color: red;
}
</style>
然后根据条件使用此类:
And then use this class according to the condition:
<div data-ng-class="{'red-background':item.selected}">{{item.name}}</div>
(不要忘记类名周围的单引号,它们很容易被忽略)
(don't forget the single quotes around the class name, they are easily overlooked)
这篇关于伍式有条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文