2015-12-29 36 views
1

on click anchor如何切換子元素類?如何使用angularjs切換子元素類

我已經在我的錨點上有一個點擊功能:點擊如何把「glyphicon-chevron-down」變成「glyphicon-chevron-up」?

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

回答

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

它不工作:在默認情況下它與 '上升',但在點擊其不切換!! :) View More Krish

+0

我們需要在toggleList函數內保留這個$ scope.getClass嗎? – Krish

+1

@Krish可以請你看看編輯答案 –