我有HTML代码:
<span id="id_1" ng-click="checkActivity(1)" class="item list-category-item active ">Bga
</span>
如何更改内部元素的CSS类:
$scope.checkActivity = function(id){}
答案 0 :(得分:1)
将您的ng-click修改为ng-click="checkActivity($event)"
以及
$scope.checkActivity = function(evt) {
angular.element(evt.currentTarget).addClass('myClass');
};
工作演示HERE
答案 1 :(得分:0)
您可以使用ng-class
动态添加类。
演示
angular.module("app",[])
.controller("ctrl",function($scope){
$scope.checkActivity = function(id){
$scope.id = id
}
})
&#13;
.sample{
color:red;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<span id="id_1" ng-click="checkActivity(1)" class="item list-category-item active" ng-class="{'sample':id}">Bga
</span>
</div>
&#13;
答案 2 :(得分:0)
您可以使用ng-class指令更改元素的类。