Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下用于初始化timeago插件的指令。
Directives.directive('timeago', function() { return function(scope, element, attrs) { $(element).attr('title', scope.post.utc_posted); $(element).timeago(); } });
我如何$log在返回的函数中使用/传递?
$log
您可以按正常方式注入它。BTWelement已经是一个 jQuery 变量并且不需要$(element)- 前提是您在 Angular 之前加载 jQuery。
element
$(element)
Directives.directive('timeago', function($log) { return { link: function(scope, element, attrs) { element.attr('title', scope.post.utc_posted); element.timeago(); } } });