2

我试图从 3 个按钮中添加/删除一个 calss,由于某种原因,有时需要不止一次点击才能工作

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

麻烦:

http://plnkr.co/QuXPziBWUgmiHcmcqC4F

4

2 回答 2

5

change

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

to

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

You have the ng-click on the actual icon and not on the entire button

于 2013-06-22T21:29:48.933 回答
0

尝试用spanusingon-tap事件包装图标:

    <span on-tap="select('slide')">
        <i class="icon-circle-arrow-up" ng-class="{active: 'slide' == selected}"></i>
    </span>
于 2015-06-15T10:44:27.153 回答