我开始尝试使用AngularJS。 现在我觉得我有一个ng-class的新手问题。 我正在尝试更改令人敬畏的字体图标的颜色。
<div ng-controller="MyCtrl">
<i ng-class="{'test': item.active}" class="fa fa-bullhorn"></i>
我有一个复选框,并通过ng-model绑定到参数
<div class="checkboxes">
<form>
<span ng-repeat="item in items">
<input type="checkbox" ng-model="item.active"> {{item.name}}<br>
</span>
</form>
</div>
</div>
当我点击复选框时,范围如下:
[{"category":"category1","name":"Item1","active":true}]
但是i元素的类只是“fa fa-bullhorn”。
颜色处于开始黑色,css类测试看起来像
.test{
color: red;
}
有人能帮助我吗?
答案 0 :(得分:0)
ng-repeat="item in items"
中是否存在该图标?如果没有,&#34; item&#34;在图标的上下文中不存在。
答案 1 :(得分:0)
<i ng-class="{'test': item.active}" class="fa fa-bullhorn"></i>
item.active 应该在转发器里面
<span ng-repeat="item in items">
<input type="checkbox" ng-model="item.active"> {{item.name}} {{item.active}}
<i ng-class="{'test': item.active}" class="fa fa-bullhorn"></i><br>
</span>