AngularJS ngRepeat指令没有编译选项 [英] AngularJS ngRepeat directive does not have compile option

查看:137
本文介绍了AngularJS ngRepeat指令没有编译选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得源$ C ​​$ C ngRepeat的没有编制的选项=htt​​p://docs.angularjs.org/guide/compiler相对= nofollow的> HTML编译器

I find the source code of ngRepeat does not have compile option mentioned in the guide of HTML Compiler.

我疑惑这个....

谁能告诉我为什么......

Who can tell me why...

推荐答案


  • 当使用transclude, $编译编译transcluded元素,然后提供了一个 childTranscludeFn 函数链接功能该指令为(以指令的控制器或$ transclude)的第五个参数

  • 此函数用于创建相同的已编译模板的多个克隆。

  • 当它被transcluded它只编译一次。

ngRepeat has a transclude option.

  • When using transclude , $compile compiles the transcluded element, and then provide a childTranscludeFn function to the linking function of the directive as the fifth argument (or $transclude in a directive's controller)
  • This function is used to create multiple clones of the same compiled template.
  • It is only compiled once when it's being transcluded.
  • if (directiveValue = directive.transclude) {
    
      // some code
    
      if (directiveValue == 'element') {
    
        // some code
    
        childTranscludeFn = compile($template, transcludeFn, terminalPriority,
                                    replaceDirective && replaceDirective.name, {
                                      // some comments
                                      nonTlbTranscludeDirective: nonTlbTranscludeDirective
                                    });
      } else {
         // some code
         childTranscludeFn = compile($template, transcludeFn);
      }
    }
    

    ngRepeat


    • 该指令手表变化的收集

    • 在变化,它遍历所有的藏品寻找新添加的项目(或删除项目)

    • 它克隆trancluded内容到新的子范围,为每一个新的项目(使用$ transclude)

    • var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
        var NG_REMOVED = '$$NG_REMOVED';
        var ngRepeatMinErr = minErr('ngRepeat');
        return {
          transclude: 'element',
          priority: 1000,
          terminal: true,
          $$tlb: true,
          link: function($scope, $element, $attr, ctrl, $transclude){
      
              // some code
      
              $scope.$watchCollection(rhs, function ngRepeatAction(collection){
      
                // some code
      
                for (index = 0, length = collectionKeys.length; index < length; index++) {
      
                  // some code
      
                  if (!block.scope) {
                    $transclude(childScope, function(clone) {
      
                      // some code
      
                    });
                  }
                }
      
                // some code
              });
          }
        };
      

      这篇关于AngularJS ngRepeat指令没有编译选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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