1. 程式人生 > >在ng-repeat中使用ng-click為元素新增class

在ng-repeat中使用ng-click為元素新增class

HTML

<div>
                <ul>
                    <li ng-repeat='x in date' ng-click='addClass(x)' ng-class='active:x.toggle>
                     </li>
                </ul>
        </div>

CSS

 .active{
            background-color:red;
        }      


JS

$scope.addClass = function(x){
                x.toggle = !x.toggle                
            }