Undefined touch using ngDraggable (AngularJS)
I am developing an app with AngularJS and a component called ngDraggable but I am having problems with touch events. When the touch event for drag is fired, the console displays an error:
Uncaught TypeError: Cannot read property '0' of undefined ngDraggable.js:118
onlongpress ngDraggable.js:118
(anonymous function) ngDraggable.js:95
I have already tried to debug the code and the variable evt
does not have an array touches
like in the example codes.
Does anyone have any ideas how I can solve this problem?
Below is the snippet where the code is the problem:
var onlongpress = function(evt) {
if(! _dragEnabled)return;
evt.preventDefault();
element.addClass('dragging');
offset = _privoffset(element);
element.centerX = element[0].offsetWidth / 2;
element.centerY = element[0].offsetHeight / 2;
_mx = (evt.pageX || evt.touches[0].pageX); // <---- This is the line the problem occurs
_my = (evt.pageY || evt.touches[0].pageY);
_mrx = _mx - offset.left;
_mry = _my - offset.top;
if (_centerAnchor) {
_tx = _mx - element.centerX - $window.pageXOffset;
_ty = _my - element.centerY - $window.pageYOffset;
} else {
_tx = _mx - _mrx - $window.pageXOffset;
_ty = _my - _mry - $window.pageYOffset;
}
[...]
+3
source to share