AngularJS: How to get directive's name in the linking function?

angularjs, angularjs-directive

Solution

Simply define it outside the injection:

var name = 'myDirective';
app.directive(name, function() {
  return {
    link: function(scope, element, attrs) {
      console.log(name); // --> myDirective
    }
  };
});

Problem

I would like to use directive's name inside the linking function. How could I get it? ``` app.directive('myDirective', function() { return { link: function(scope, element, attrs) { // How could I get directive's name here (i.e. 'myDirective')? } }; }); ```

Original source