我试图使用Angular的“装饰器”功能来添加功能到一些指令.假设我的指令的名字是myDirective.我的代码如下所示:
angular.module('app').config([ '$provide',function($provide) { return $provide.decorator('myDirective',[ '$delegate','$log',function($delegate,$log) { // TODO - It worked! Do something to modify the behavior $log.info("In decorator"); } ]); }
]);
我不断得到这个消息:
Uncaught Error: [$injector:unpr] Unknown provider: myDirectiveProvider from app
本文介绍了如何使用指令中的decorator().
原文链接:https://www.f2er.com/angularjs/142658.html您只需将“指令”作为名称的后缀.因此,在我的例子中,我应该这样做
return $provide.decorator('myDirectiveDirective',['$delegate',$log) { // TODO - It worked! Do something to modify the behavior $log.info("In decorator"); // Article uses index 0 but I found that index 0 was "window" and index 1 was the directive var directive = $delegate[1]; }
http://angular-tips.com/blog/2013/09/experiment-decorating-directives/