如果我有一些内部使用ng-repeat的模板并将其包含在ng-include中,实际会发生什么? 将包含已完成ng-repeat的模板,或未完成ng-repeat的模板(以及包括ng-repeat之后的模板)?
答案 0 :(得分:1)
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的模板(并且在包含ng-repeat之后 完成)