链接功能不叫 [英] Link function not called

查看:110
本文介绍了链接功能不叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下定义指令 -

I have a directive defined as following -

.directive('codesection', ['$compile', function ($compile) {
  return {
      restrict: 'E',
      scope: { current: '=', parent: '=', index: '=', params: '=' },
      controller: ['Messages', '$scope', 'Modals', 'framewidth', '$http', '$rootScope', function (Messages, $scope, Modals, framewidth, $http, $rootScope) {
          //code
      }],
      link: function (scope, element, attr) {              
          element.bind('mouseover', function (ev) {
              ev.stopPropagation();

              var wrappers = angular.element(document.getElementsByClassName('codesection'));
              angular.forEach(wrappers, function (value, key) {
                  angular.element(value).children('span').removeClass('br');
              });

              element.children('.codesection').children('span').addClass('br');
          });

      },
      compile: function (tElement, tAttr, transclude) {
          var contents = tElement.contents().remove();
          var compiledContents;
          return function (scope, iElement, iAttr) {
              if (!compiledContents) {
                  compiledContents = $compile(contents, transclude);
              }
              compiledContents(scope, function (clone, scope) {
                  iElement.append(clone);
              });

          };
      },
      templateUrl: './partials/directives/codesection.html',          
      replace: true
  }
}])

我遇到的问题是,链接功能不会被调用。谢谢!

The issue I am having is that Link functions is never called. Thank you!

P.S。究其原因,编译逻辑是,该指令是递归的。

P.S. The reason for the Compile logic is that the directive is recursive.

推荐答案

如果你的意思是链接:功能(范围,元素,属性){不叫然后这是pretty明确:编译函数已经返回一个链接功能。什么是定义为链接:不再重要而被忽略

If you mean that link: function (scope, element, attr) { isn't called then it's pretty clear: The compile function already returns a link function. What is defined as link: doesn't matter anymore and is ignored.

这篇关于链接功能不叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆