I have a directive that contains input with two arrow that increments/decrements numbers.
I'd like to increase/decrease the numbers continuously when the user uses a long click, how can i do that?
directive:
'use strict';
(function (module) {
var vlIncrementor = function () {
return {
templateUrl: 'assets/angular-client/app/html/common/incrementor/vlIncrementor.html',
scope: { model: '=ngModel' },
controller: function ( $scope ) {
$scope.increment = function ( ) {
$scope.model++;
};
$scope.decrement = function () {
$scope.model--;
};
}
};
};
module.directive('vlIncrementor', vlIncrementor);
}(angular.module('html.common')));
HTML:
<div class="vl-increment">
<i class="fa fa-caret-left fa-lg center" ng-class="{disabled: model === 0}" ng-click="decrement()"></i>
<input type="text" ng-model="model"/>
<i class="fa fa-caret-right fa-lg center" ng-click="increment()"></i>
</div>
I tried adding a link function with this code, but it didn't work (it incremented by one like a regular click):
link: function ( scope , el) {
$(el ).find('.fa-caret-left').mouseup(function(){
clearTimeout(pressTimer)
// Clear timeout
return false;
}).mousedown(function(){
// Set timeout
pressTimer = window.setTimeout(function() {
scope.$apply( function () {
scope.model--;
});
},1000);
return false;
});
}