There are several things you can do to get a directive element.
Event item
If you need to pass an element in an event, you can create a callback that can pass an element back. If you donβt need a link to it all the time, this is the preferred method.
In the return object in the directive add something like
scope:{ elementclicked: "&" }
In the template of your directive you can add
<....... ng-click="ElementClicked(event)"........>
In your directive controller, you can now process the click and pass the results
$scope.ElementClicked = function ($event) { if ($scope.elementclicked != undefined) { elementclicked({ event: $event }); } }
Now you pass your callback, like any other, to the directive.
<yourDirective elementclicked="MyFunction(event)" ....>
Element on connection
If you need a link at creation time, you can also do this. If you go to a data structure, such as settings, you can set it in a binding event. When you contact the directive, just set the element.
scope:{ settings:"=" }, link:function(scope,element){ scope.$watch('settings',function(){ if(scope.settings!=undefined){ scope.settings.element=element; } } }
This will keep track of when the settings are bound and set the item property. The big drawback is that you add the property to the passed object, but if it is intended for a directive inside the directive or if it is just your project, this should be good.
Another way to do this is to use the first method and create an elementlinked (element) callback and run it after binding the area.