[英]Angular: increase counter on long press
我有一個指令,其中包含帶有兩個箭頭的輸入,兩個箭頭用於遞增/遞減數字。
我想在用戶長按時連續增加/減少數字,我該怎么做?
指示:
'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>
我嘗試使用此代碼添加鏈接功能,但是沒有起作用(它像常規點擊一樣增加了一個):
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;
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.