Listen to tap events using angular.element

Hi guys,

I would like to listen on tap events, like
angular.element('.selector').on('tap', function(){ // do something });

Can you suggest a way to use the internal api to listen on those tap events? I need to implement something in a custom directive.

Thanks,
Jonathan

This worked with me angular.element(document').on('tap', '.selector', function(){ // do something }); but I have jQuery Loaded beside angular. Thanks

Try this:

angular.module('MyApp').directive('gotTapped', ['$ionicGesture', function($ionicGesture) {

    return {
        restrict: 'A',
        link: function($scope, $element, $attr) {

            $ionicGesture.on('tap', function(e) {
                console.log('I got Tapped!')
            }, $element);
        }
    }
}])
<div got-tapped>Tap Me!</div>
2 Likes

Here’s a sample.

Be sure to change the console open.

Thanks @Calendee :), It wasn’t noticing that it’s documented.

Great Sample, Works like a magic