4

I created this plunker http://plnkr.co/edit/s8p2KtW8YnPqU557J78k?p=preview demonstrating what I would consider the most basic way to leverage hammerjs and its gesture events from within angular2 & typescript as an external library.

_.each( this.actors, function(actor){

        var myElement = document.getElementById(actor.id);
        myElement.style.backgroundColor = actor.color;

        var hammertime = new window.Hammer(myElement);


        hammertime.on('panright', function(ev) {

            var target = ev.target;
            var actorName = target.getAttribute('data-actor');

            console.log("pan actorName: ", actorName);
        });


        hammertime.on('tap', function(ev) {

            var target = ev.target;
            var actorName = target.getAttribute('data-actor');

            console.log("tap actorName: ", actorName);
        });

        hammertime.on('swipe', function(ev) {

            var target = ev.target;
            var actorName = target.getAttribute('data-actor');

            console.log("swipe actorName: ", actorName);
        });

   });

I can see tap and pan events but not the swipe events. Any ideas why? For my purposes, I can simply treat panleft or panright as a swipeleft or swiperight event but its strange that the swipe events don't seem to be captured consistently like pan.

headwinds
  • 1,781
  • 15
  • 26
  • I believe the event names are "swiperight" and "swipeleft". Take a look at http://stackoverflow.com/questions/35728451/using-mobile-events-in-angular2 – Diego Ledesma Mar 16 '16 at 19:10
  • UPDATE: Sorry I didn't see that in your plunker you were using the correct events. Do you need to have pan and swipe events at the same time? Pan runs after swipe. Try with just swipe and it should work. – Diego Ledesma Mar 16 '16 at 19:20
  • No dice. I commented out the pan and taps events isolating the swipe and still nothing. I also tried increasing the size of the div thinking swipe may need a larger arc. To me, a swipe should be drag quickly and then release... I need swipe gestures in my mobile app and pan is working so far. I just exit as soon as the pan begins and consider that a swipe. – headwinds Mar 19 '16 at 16:50

0 Answers0