如何使用angularjs切换子元素类

how to toggle the child element class using angularjs

本文关键字:元素 何使用 angularjs      更新时间:2023-09-26

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

我已经在我的锚上有一个点击功能:点击时如何将"字形V形向下"切换为"字形V字形向上"?

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

您可以拥有

标记

<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';
}