我怎么能聆听到AngularJS点击和保持? [英] How can I listen for a click-and-hold in AngularJS?
本文介绍了我怎么能聆听到AngularJS点击和保持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经做了一次康特它可以增加或通过点击一个按钮,减少时间。不过,我想,当我点击并按住按钮的时间价值将继续攀升。
I have made a time conter which allows you to increase or decrease the time by clicking a button. I would like however that when I click and hold the button the value of the time would keep climbing.
所以目前如果你看到我的 Plunkr 每次我点击了按钮值增大,但是我想这个,所以当我按住鼠标键的值增加 1,2,3,4,5,6,7,8
,直到我释放按钮。
So currently if you see my Plunkr each time I click the up button the value increases but I want this so when I hold the button down the value increases 1,2,3,4,5,6,7,8
until I release the button.
我怎么能做到这样呢?
推荐答案
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>
使用NG-MOUSEDOWN和$区间NG-鼠标松开指令
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() {
promise = $interval(function () {
scope.Time = scope.Time + 1;
}, 100);
};
scope.mouseUp = function () {
$interval.cancel(promise);
};
}
};
});
这篇关于我怎么能聆听到AngularJS点击和保持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文