您当然可以使用装饰器来添加功能。我快速做出了示范。基本上,在装饰器主体中,将您自己的编译函数替换为用于自定义逻辑的编译函数(在示例中,如果存在track属性,则绑定到click事件),然后调用原始编译函数。这是代码段:
$provide.decorator('ngClickDirective', function($delegate) { var original = $delegate[0].compile; $delegate[0].compile = function(element, attrs, transclude) { if(attrs.track !== undefined) { element.bind('click', function() { console.log('Tracking this'); }); } return original(element, attrs, transclude); }; return $delegate;})


