我这里有一个标签:
https://plnkr.co/edit/EKpqNwQEHHHiFoiv43s3
我在手机或平板电脑上遇到了一个问题,我的ng-touch在鼠标向下而不是在鼠标向上发射,导致递增到无限,这是不希望的。
代码:$scope.mouseDown = function(dir) { //this function fires when I press down on a phone
promise = $interval(function() {
if (dir === "up")
$scope.quantity++;
else
$scope.quantity--;
}, 100);
};
$scope.mouseUp = function() { //this function doesn't seem to fire when I stop the press on a phone
$interval.cancel(promise);
};
mouseup
在触摸设备上不开火。不幸的是,ngTouch
没有给你绑定触摸事件的指令。您需要抓取一个自定义指令,允许您绑定touchstart
和touchend
事件。有一些人在那里。我创建了一个要点,我写了一个在我的几个项目中很有效的要点:
这样,您就可以像绑定ng-mousedown
和ng-mouseup
一样在标记中绑定flux-touchstart
和flux-touchend
。