简体   繁体   English

AngularJS中的first,ng-include或ng-repeat是什么?

[英]What is first, ng-include or ng-repeat in AngularJS?

If I've got some template with ng-repeat inside and include it with ng-include, what actually will happen? 如果我有一些带有ng-repeat的模板并将其包含在ng-include中,那么实际上会发生什么? Template with completed ng-repeat will be included, or template without completed ng-repeat (and after include ng-repeat will be completed)? 包含完整ng-repeat的模板将被包含,还是包含未完整ng-repeat的模板(包含ng-repeat之后将被完成)?

ngInclude directive first attach the html that return from the template to the html DOM. ngInclude指令首先将从模板返回的html附加到html DOM。 Then it compiles it's content. 然后编译它的内容。

As you can see in the source code of the ngInclude 如您所见,在ngInclude的源代码中

// This directive is called during the $transclude call of the first `ngInclude` directive.
// It will replace and compile the content of the element with the loaded template.
// We need this directive so that the element content is already filled when
// the link function of another directive on the same element as ngInclude
// is called.
var ngIncludeFillContentDirective = ['$compile',
  function($compile) {
    return {
      restrict: 'ECA',
      priority: -400,
      require: 'ngInclude',
      link: function(scope, $element, $attr, ctrl) {
        if (/SVG/.test($element[0].toString())) {
          // WebKit: https://bugs.webkit.org/show_bug.cgi?id=135698 --- SVG elements do not
          // support innerHTML, so detect this here and try to generate the contents
          // specially.
          $element.empty();
          $compile(jqLiteBuildFragment(ctrl.template, document).childNodes)(scope,
              function namespaceAdaptedClone(clone) {
            $element.append(clone);
          }, {futureParentElement: $element});
          return;
        }

        $element.html(ctrl.template);
        $compile($element.contents())(scope);
      }
    };
  }];

Look at the rows 看行

    $element.html(ctrl.template);
    $compile($element.contents())(scope);

It means it first add it to the DOM, and then compile it. 这意味着它首先将其添加到DOM中,然后进行编译。

In the bottom line, You described it as 在底线中,您将其描述为

It's a template without completed ng-repeat (and after include ng-repeat will be completed) 这是一个没有完成ng-repeat的模板(在完成include ng-repeat之后将完成)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM