簡體   English   中英

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

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

如果我有一些帶有ng-repeat的模板並將其包含在ng-include中,那么實際上會發生什么? 包含完整ng-repeat的模板將被包含,還是包含未完整ng-repeat的模板(包含ng-repeat之后將被完成)?

ngInclude指令首先將從模板返回的html附加到html DOM。 然后編譯它的內容。

如您所見,在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);
      }
    };
  }];

看行

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

這意味着它首先將其添加到DOM中,然后進行編譯。

在底線中,您將其描述為

這是一個沒有完成ng-repeat的模板(在完成include ng-repeat之后將完成)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM