[英]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.