ANGULARJS Development Mobile End page, make mobile end page must be inseparable from, Touchstart, Touchmove, touchend these actions, but Angularjs provided Ng-touch module is not ngtouchstart this touch screen event , so that the click Delay, so today is the introduction of another Ng-touch written by foreign people, to achieve the mobile end of the Touchstart,touchmove,touchend these events used, as usual, the introduction of the following code, and then injected into the module Ngtouch, just to Ng-click change it to Ng-touchstart.
"use strict";
angular.module("ngTouch", [])
.directive("ngTouchstart", function () {
return {
controller: ["$scope", "$element", function ($scope, $element) {
$element.bind("touchstart", onTouchStart);
function onTouchStart(event) {
var method = $element.attr("ng-touchstart");
$scope.$apply(method);
}
}]
}
})
.directive("ngTouchmove", function () {
return {
controller: ["$scope", "$element", function ($scope, $element) {
$element.bind("touchstart", onTouchStart);
function onTouchStart(event) {
event.preventDefault();
$element.bind("touchmove", onTouchMove);
$element.bind("touchend", onTouchEnd);
}
function onTouchMove(event) {
var method = $element.attr("ng-touchmove");
$scope.$apply(method);
}
function onTouchEnd(event) {
event.preventDefault();
$element.unbind("touchmove", onTouchMove);
$element.unbind("touchend", onTouchEnd);
}
}]
}
})
.directive("ngTouchend", function () {
return {
controller: ["$scope", "$element", function ($scope, $element) {
$element.bind("touchend", onTouchEnd);
function onTouchEnd(event) {
var method = $element.attr("ng-touchend");
$scope.$apply(method);
}
}]
}
});