如何通过单击角度不同的按钮来添加和删除类?

时间:2015-02-11 11:47:51

标签: angularjs

这里在ng-class中我使用class1,点击该颜色变为红色,如果我点击关闭按钮,该类应该被删除。我添加了课程,但我不知道如何通过关闭按钮删除。有人帮助我。

HTML

        <div class="name-awards"   ng-class="class1" ng-click="addAssociate('John M Kennady1 (111111)');associateInput = ''; ">
            <p class="name-awards-name">John M Kennady1</p>
            <p class="name-awards-id">(111111)</p>
        </div>        

         <div class="name-awards" ng-click="addAssociate('John M Kennady2 (222222)');associateInput = '';">
            <p class="name-awards-name">John M Kennad2y</p>
            <p class="name-awards-id">(123456)</p>

        </div>   
        <div class="addedAssociates">
            <div class="adass-close" ng-repeat="ass in addedAssociates">{{ass}}<button class="clsbtn" ng-click="remove($index)"></button></div>
        </div>

SCRIPT

$scope.addAssociate = function(b){
if($scope.addedAssociates.indexOf(b) == -1){
$scope.addedAssociates.push(b);
 $scope.class1 = "red";
   }
}
$scope.remove = function (index) {
    $scope.addedAssociates.splice(index, 1);
    angular.element("[ng-class='class1']").removeClass("red")
 }

CSS

.red{color:red;}  .blue { color:blue;}

0 个答案:

没有答案