AngularJS - Using ngTouch within a directive for mobile devices

266 Views Asked by At

I'm using ngTouch to remove the delay on mobile devices, but on mobile devices clicking an image does nothing. On my app, clicking an image calls a directive to enlarge the images, so there is no ng-click. Here is the directive:

app.directive('imageZoom', ['ngDialog', function(ngDialog) {
    return {
        restrict: 'A',
        scope: {
            image: '='
        },
        link: function(scope, element, attr) {
            attr.$observe('ngSrc',function(img) {
                element.bind('click', function(e) {
                    e.stopPropagation();
                    if (something) {
                        doSomething();
                    } else {
                        ngDialog.open({
                           some template here
                        });
                    }
                });
            });
        }
    };
}]);

This was working fine until I introduced ngTouch so I believe there is an issue with the element.bind('click' aspect of it where it is not registering the click. It does work perfectly fine on a browser though so the directive does work.

1

There are 1 best solutions below

1
jad-panda On

Listen for element.bind('touchstart click', function(){ ... } instead of only click element.bind('click', function(){ ... }.