我想在链接函数中使用指令的名称.我怎么可以得到它?
app.directive('myDirective',function() { return { link: function(scope,element,attrs) { // How could I get directive's name here (i.e. 'myDirective')? } }; });
简单地将它定义在注射之外:
var name = 'myDirective'; app.directive(name,attrs) { console.log(name); // --> myDirective } }; });