Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 使用ng include编译动态模板_Angularjs_Angularjs Ng Include - Fatal编程技术网

Angularjs 使用ng include编译动态模板

Angularjs 使用ng include编译动态模板,angularjs,angularjs-ng-include,Angularjs,Angularjs Ng Include,我坚持以下情况。我有一个带有ng include的动态模板(template.html) <div data-ng-include data-src="childTemplate">{{ var }}</div> 在这种情况下,tpl只包含已编译的父模板,而不包含子模板。我试着去做 <div data-ng-include data-src="childTemplate" onload="templateLoaded()"></div> 在这种

我坚持以下情况。我有一个带有ng include的动态模板(template.html)

<div data-ng-include data-src="childTemplate">{{ var }}</div>
在这种情况下,tpl只包含已编译的父模板,而不包含子模板。我试着去做

<div data-ng-include data-src="childTemplate" onload="templateLoaded()"></div>

在这种情况下,child.html已加载但未包含到父模板中。如何解决这个任务?谢谢

tpl
现在是在DOM上编译的元素。 您应该做的是,在编译
child.html
之后,将其添加到DOM中

因此,您可以执行以下操作:

tpl = $compile($templateCache.get('template.html'))($scope);
$scope.contentLoaded = function() {
    var child = $compile($templateCache.get('child.html'))($scope);
    tpl.appendChild(child);
}

如果您想添加
child.html
模板作为
tpl
子级的最后一个,这可能会起作用(如果没有,您应该导航它)。

您可以为您的问题创建plnkr吗?下面是一个简单的示例,说明为什么这个答案为-1,您可以解释为什么给@Michael-1。是因为他说了些假话还是因为他离题了?或者类似的,所以我知道为什么我需要拒绝这个答案。
tpl = $compile($templateCache.get('template.html'))($scope);
$scope.contentLoaded = function() {
    $compile($templateCache.get('child.html'))($scope)
}
tpl = $compile($templateCache.get('template.html'))($scope);
$scope.contentLoaded = function() {
    var child = $compile($templateCache.get('child.html'))($scope);
    tpl.appendChild(child);
}