Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get the current element

Tags:

angularjs

It's possible to intercept current event object in ng-click like handlers by using $event property.

But is it possible to get the element from which the method has been called?

like for example:

<div ng-controller='myController'>
  <div>{{distortThatDiv($element)}}</div>
</div>
like image 323
iLemming Avatar asked Dec 11 '12 16:12

iLemming


1 Answers

If you're going to manipulate the DOM, you really should be using a directive. However, if you have the $event, you can get the raw element the event was triggered on easily:

$scope.clickHandler = function($event) {
   var element = $event.target;
};
like image 113
Michelle Tilley Avatar answered Sep 19 '22 18:09

Michelle Tilley