【问题标题】:how to toggle the child element class using angularjs如何使用angularjs切换子元素类
【发布时间】:2015-12-29 20:02:10
【问题描述】:

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

我的锚点上已有一键点击功能:点击时如何将“glyphicon-chevron-down”切换为“glyphicon-chevron-up”?

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

【问题讨论】:

    标签: javascript angularjs ng-class


    【解决方案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';
    }
    

    【讨论】:

    • 它不起作用:默认情况下它带有'up'但点击它不切换! :) 查看更多 跨度>
    • 我们是否需要将这个 $scope.getClass 保留在 toggleList 函数中?
    • @Krish $scope 基本上用于绑定,然后您可以直接在角度指令中在html上使用范围变量。
    猜你喜欢
    • 2016-12-17
    • 1970-01-01
    • 2016-06-16
    • 2016-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多