如何使用angularjs切换子元素类

时间:2015-12-29 07:46:30

标签: javascript angularjs ng-class

单击锚点如何切换子span元素类?

我的锚点上已经有一个点击功能:点击如何切换" glyphicon-chevron-down" to" glyphicon-chevron-up" ?

    <a ng-click="toggleList()">
     View More <span class="glyphicon glyphicon-chevron-down"></span>
    </a>

1 个答案:

答案 0 :(得分:1)

你可以

<强>标记

<a ng-click="toggleList()">
     View More <span class="glyphicon" ng-class="getClass()"></span>
</a>

<强>代码

$scope.toggleList = function(){
   //other logic here
   $scope.isDown = !$scope.isDown; 
}

$scope.getClass = function(){
    return $scope.isDown ? 'glyphicon-chevron-down': 'glyphicon-chevron-up';
}