加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

$log(或AngularJS指令中的其他服务)

发布时间:2020-12-17 07:07:25 所属栏目:安全 来源:网络整理
导读:我有以下用于初始化 timeago插件的指令. Directives.directive('timeago',function() { return function(scope,element,attrs) { $(element).attr('title',scope.post.utc_posted); $(element).timeago(); }}); 我如何在我返回的函数中使用/传递$log? 解决
我有以下用于初始化 timeago插件的指令.

Directives.directive('timeago',function() {
   return function(scope,element,attrs) {
       $(element).attr('title',scope.post.utc_posted);
       $(element).timeago();
   }
});

我如何在我返回的函数中使用/传递$log?

解决方法

你可以按正常方式注射它. BTW元素已经是一个jQuery变量,不需要$(元素) – 提供你在Angular之前加载jQuery.

Directives.directive('timeago',function($log) {
   return {
    link: function(scope,attrs) {
       element.attr('title',scope.post.utc_posted);
       element.timeago();
     }
   }
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读