ng-click无法正常工作

时间:2013-06-22 21:23:37

标签: class angularjs angularjs-ng-click

我试图从3个按钮添加/删除一个类, 出于某种原因,它有时需要多次点击才能工作

<a class="button small">
  <i class="icon-circle-arrow-up" ng-click="select('slide')" ng-class="{active: 'slide' ==     selected}"></i>
</a>
<a class="button small">
  <i class="icon-resize-horizontal" ng-click="select('wave')" ng-class="{active: 'wave' == selected}"></i>
</a>
<a class="button small">
  <i class="icon-repeat" ng-click="select('role')" ng-class="{active: 'role' == selected}"></i>
</a>

javascript:

myApp.controller("TodoCtrl", function($scope, $http) {
  $scope.slide = "one";
  $scope.animate = "slide";
  $scope.selected = "slide";
  return $scope.select = function(item) {
   $scope.selected = item;
   return $scope.animate = item;
 };
});

plunker:

http://plnkr.co/QuXPziBWUgmiHcmcqC4F

2 个答案:

答案 0 :(得分:5)

更改

      <a class="button small">
        <i class="icon-circle-arrow-up" ng-click="select('slide')" ng-class="{active: 'slide' == selected}"></i>
      </a>

      <a class="button small" ng-click="select('slide')">
        <i class="icon-circle-arrow-up"  ng-class="{active: 'slide' == selected}"></i>
      </a>

您可以点击实际图标而不是整个按钮

答案 1 :(得分:0)

尝试使用span事件使用on-tap包装图标:

    <span on-tap="select('slide')">
        <i class="icon-circle-arrow-up" ng-class="{active: 'slide' == selected}"></i>
    </span>