【发布时间】:2016-09-21 13:29:26
【问题描述】:
我正在浏览这个doc,我的困惑是link.apply(this,attrs)中的“this”是什么。有人可以帮忙吗?
$provide.decorator('fooDirective', function($delegate) {
var directive = $delegate[0];
directive.scope.fn = "&";
var link = directive.link;
directive.compile = function() {
return function(scope, element, attrs) {
link.apply(this, arguments);
element.bind('click', function() {
scope.$apply(function() {
scope.fn();
});
});
};
};
return $delegate;
});
});
当我尝试使用控制台调试器对其进行调试时,'this' 在链接函数运行时未定义。
【问题讨论】:
标签: angularjs angular-directive angular-decorator