2

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

プランカー:

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 に答える