DEMO
<span class="time">{{ Time | timeFilter }}</span>
<div class="btn-group btn-group-sm">
<button class="btn btn-default" ng-mousedown='mouseDown()' ng-mouseup="mouseUp()">
<i class="fa fa-caret-up"></i>
</button>
<button class="btn btn-default" ng-click="Time = Time - 1">
<i class="fa fa-caret-down"></i>
</button>
</div>
Use ng-mouseDown and ng-mouseup directive with $interval
app.directive('time', function ($interval) {
return {
templateUrl: 'time.html',
restrict: 'E',
scope: {
Time: '=value'
},
link: function (scope, element, attrs) {
element.addClass('time');
var promise;
scope.mouseDown = function() {
if(promise){
$interval.cancel(promise);
}
promise = $interval(function () {
scope.Time++;
}, 100);
};
scope.mouseUp = function () {
$interval.cancel(promise);
promise = null;
};
}
};
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…