Created
September 7, 2013 15:20
-
-
Save lpaulger/6476510 to your computer and use it in GitHub Desktop.
A simple quantity spinner for angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('__directives').directive('__Quantity', [ | |
function() { | |
return { | |
restrict: "E", | |
scope: { | |
quantity: '=' | |
}, | |
replace: true, | |
templateUrl: 'templates/quantitySpinner.html', | |
link: function(scope, element, attrs) { | |
scope.increase = function() { | |
scope.quantity = parseInt(scope.quantity, 10); | |
scope.quantity += 1; | |
}; | |
scope.decrease = function() { | |
if (scope.quantity > 0) { | |
scope.quantity = scope.quantity - 1; | |
} | |
}; | |
} | |
}; | |
} | |
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="qty-spinner"> | |
<span ng-click="decrease()"><i class="icon-chevron-sign-left"></i></span> | |
<input ng-model="quantity"></input> | |
<span ng-click="increase()"><i class="icon-chevron-sign-right"></i></span> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment