angularjs在同一页面上有几个类似的按钮

时间:2018-08-28 08:38:33

标签: angularjs

使用AngularJS脚本。只有一个类似的按钮可以工作,但需要在同一个页面上显示多个按钮。有人可以检查如何实施吗?下面是代码:

html:

      <div class = "likes" ng-app="myApp" ng-controller="Main">
         <div class="cont">
         <a href="#" ng-click="doVote()">
      <i class="glyphicon" ng-class="(like.userVotes==1) ? 'glyphicon- 
          heart': 'glyphicon-heart-empty'"></i>
       <span ng-model="like.votes">{{like.votes}}</span>
       </a>
          </div>
                </div>

JavaScript:

   var myApp = angular.module('myApp', []).
   controller('Main', ['$scope', function ($scope) {
   $scope.like = {};
   $scope.like.votes = 0;
   $scope.doVote = function () {
   if ($scope.like.userVotes == 1) {
   delete $scope.like.userVotes;
   $scope.like.votes--;
   } else {
   $scope.like.userVotes = 1;
   $scope.like.votes++;
       }
     };
    }]);

0 个答案:

没有答案