角 - 装饰指令 [英] Angular - Decorating Directives
问题描述
我试图用角的装饰功能,将功能添加到一些指令。假设我的指令的名字是myDirective。我的code是这样的:
I'm trying to use Angular's "decorator" capability to add functionality to some directives. Assume that my directive's name is myDirective. My code looks like this:
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");
}
]);
}
]);
我不断收到这样的信息:
I keep getting this message:
Uncaught Error: [$injector:unpr] Unknown provider: myDirectiveProvider from app
要尽我最大的能力,该指令已被装饰函数运行时注册。任何有识之士将AP preciated!
To the best of my ability, the directives are already registered by the time the decorator function runs. Any insight would be appreciated!
推荐答案
本文介绍了如何可以,事实上,使用装饰()与指令。
This article shows how you can, in fact, use decorator() with directives.
您只需要包括指令为后缀名。因此,在我的例子中,我应该做的事情。
You just have to include "Directive" as the suffix for the name. Hence, in my example I should have been doing
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];
}
<一个href=\"http://angular-tips.com/blog/2013/09/experiment-decorating-directives/\">http://angular-tips.com/blog/2013/09/experiment-decorating-directives/
这篇关于角 - 装饰指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!