Skip to content

Instantly share code, notes, and snippets.

@adrianvlupu
Last active August 29, 2015 14:02
Show Gist options
  • Save adrianvlupu/0ff9e3074a04867345cb to your computer and use it in GitHub Desktop.
Save adrianvlupu/0ff9e3074a04867345cb to your computer and use it in GitHub Desktop.
Numeric Spinner Directive
<input id="{{id}}" type="text" name="" ng-model="value" />
<span class="add" ng-click="add()">+</span>
<span class="remove" ng-click="subtract()">-</span>
/// <reference path="../_references.js" />
mainModule.directive('numericSpinner', function () {
return {
restrict: 'E',
templateUrl: '/Application/Directives/NumericSpinner.html',
scope: {
minValue: '@minValue',
defaultValue: '@defaultValue',
id: '@textId',
value: '=ngModel'
},
link: function ($scope, $elem, $attrs) {
$scope.value = $scope.defaultValue;
$scope.add = function () {
$scope.value++;
};
$scope.subtract = function () {
if ($scope.value > $scope.minValue)
$scope.value--;
};
$elem.find('input').bind('mousewheel DOMMouseScroll', function (event, delta) {
if (event.originalEvent.wheelDelta > 0 || event.originalEvent.detail < 0) {
$scope.value++;
$scope.$apply();
}
else {
if ($scope.value > $scope.minValue) {
$scope.value--;
$scope.$apply();
}
}
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment