![](/img/trans.png)
[英]AngularJS, ng-repeat with ng-include not rendering
[英]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.