簡體   English   中英

角度:長按增加計數器

[英]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;
                });
            }

這里已經回答類似的問題。

可能的解決方案是使用ng-mousedownng-mouseup並使用$interval來控制計數器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM