[英]Angular - Decorating Directives
我正在尝试使用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()。
您只需要包含“Directive”作为名称的后缀。 因此,在我的例子中我应该这样做
return $provide.decorator('myDirectiveDirective', ['$delegate', '$log', function($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/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.