2014-10-27 59 views
0

我真的不明白是什麼在此代碼的問題:角度自定義輸入號碼不起作用

app.directive('counter', function() { 
       return { 
        restrict: 'A', 
        scope:{}, 
        template:'<div class="item-counter"><input type="text" data-ng-model="qnt"><span class="glyphicon glyphicon-chevron-up" data-ng-click="increment()"><span class="glyphicon glyphicon-chevron-down" data-ng-click="decrement()"></span><button type="button" class="btn btn-success">Aggiungi</button></div>', 
        controller: function($scope) { 
         $scope.qnt = 1; 
         $scope.increment = function() { 
          $scope.qnt++; 
         }; 
         $scope.decrement = function() { 
          console.log($scope.qnt > 1); 
          if ($scope.qnt > 1) { 
           $scope.qnt--; 
          } 
          console.log($scope.qnt); 
         }; 
        }, 
        link: function(scope, element, attrs) { 

        } 

       }; 
      }); 

增量工程遞減不起作用。 有什麼問題?

http://plnkr.co/edit/BdFHpnrJnG4DFjTkmuZ0?p=preview

回答

3

你沒有過的增量跨任何結束標記。因此,當遞減代碼正在執行時,遞增代碼也在執行中,從而使遞減無效。

template:'<div class="item-counter"><input type="text" data-ng-model="qnt"><span class="glyphicon glyphicon-chevron-up" data-ng-click="increment()"></span><span class="glyphicon glyphicon-chevron-down" data-ng-click="decrement()"></span><button type="button" class="btn btn-success">Aggiungi</button></div>', 

更新花掉here

+0

THX我傻:) – Whisher 2014-10-27 10:52:50

+0

沒有後顧之憂!樂意效勞。 :-) – 2014-10-27 10:53:16