RyanMullins / angular-hammer

Hammer.js v2 support for AngularJS
http://ryanmullins.github.io/angular-hammer/
MIT License
188 stars 55 forks source link

How to get access to element from controller? #9

Closed fidoboy closed 9 years ago

fidoboy commented 9 years ago

I can get the target element (using event.target) but how can i get the element where the hammer directive is located? Thanks

RyanMullins commented 9 years ago

You can use standard DOM traversals to get to the parent or child element that has actually registered for the event. Does this address your problem, or am I missing something?

fidoboy commented 9 years ago

I already know that, but it could be a bit complex depending on the DOM structure. I was asking because I thought that the angular directive could expose the element in some way...

fidoboy commented 9 years ago

event.element = element before the scope.apply could solve this problem and this way expose the object allowing to use it from the app controller.

RyanMullins commented 9 years ago

That was exactly what I was just thinking. I'll take a look at it later today.

RyanMullins commented 9 years ago

In the meantime, check out the srcEvent object: http://hammerjs.github.io/api/#event-object

That might get you what you want, though I haven't actually tried to verify that at all.