Skip to content

Instantly share code, notes, and snippets.

@lpaulger
Created September 7, 2013 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lpaulger/6476510 to your computer and use it in GitHub Desktop.
Save lpaulger/6476510 to your computer and use it in GitHub Desktop.
A simple quantity spinner for angular
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;
}
};
}
};
}
])
<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