在ng-repeat中使用两次Angular ng-class

时间:2016-05-11 07:02:33

标签: angularjs angularjs-ng-repeat ng-class

是否可以在ng-class内使用ng-repeat两次?一次选择highlight一行row,另一行检查object个字符:

<ul>
      <li
        ng-repeat="item in items"
        ng-class="{'someclass' : item.Id > 10 && item.color != 'red'}" ng-class = "'selected' : $index == selected">
        {{item .name}}
      </li>
    </ul> 

由于某种原因,第二个ng-class(在此示例中为selectd)无效。 项目:

 $scope.items = [

    { Id: 1, name: "item1" , color : 'red' },
    { Id: 20, name: "item1" , color : 'blue' },
    { Id: 11, name: "item1" , color : 'white' }
 ];

1 个答案:

答案 0 :(得分:3)

将两者放在一个ng-class中 - 类似这样:

<ul>
  <li
    ng-repeat="item in items"
    ng-class="{'someclass' : item.Id > 10 && item.color != 'red', 'selected' : $index == selected}">
    {{item .name}}
  </li>
</ul>