Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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