您必须使用指令来添加和删除类
HTML:
<div ng-controller="MyCtrl">
<input type="button" active value='One' />
<input type="button" active value='Two' />
<input type="button" active value='Three' />
</div>
JS:
var app = angular.module('myApp',[]);
app.directive('active', function() {
return {
link: function(scope, element, attrs) {
element.bind('click', function() {
//Remove the active from all the child elements
element.parent().children().removeClass('active');
//Add active class to the clicked buttong
element.addClass('active');
})
},
}
});
function MyCtrl($scope) {
}
这是小提琴的链接。