這裏是我的html代碼:如何NG重複addClass
<div ng-controller="MainController">
<ul class="list-holder">
<li ng-repeat="check in checks" ng-class="{active : isSelected(check)}">
<button ng-click="setcolor(check)">{{check.name}} </button>
<button ng-click="setcolor(check)">{{check.name}} </button>
<button ng-click="setcolor(check)">{{check.name}} </button>
<hr>
</li>
</ul>
<hr>
{{selected | json}}
</div>
,這是我的控制器
function MainController($scope) {
$scope.checks = [
{name: 'sports'},
{name: 'movies'},
{name: 'Others'}
];
$scope.setcolor = function(chk) {
$scope.selected = chk;
}
$scope.isSelected = function(check) {
return $scope.check === check;
}
}
THIS IS MY CSS文件
.active {
background-color: red;
}
我w ant使用切換功能在每一行中選擇一個按鈕。假設在第一行中選擇按鈕1,在第二行按鈕2中,在第三行按鈕1中被選擇。
因爲這樣http://plnkr.co/edit/WTQREUzelTxzFUxzvOx4?p=preview – 2014-10-08 11:17:12