【发布时间】:2015-05-05 10:22:33
【问题描述】:
我有一个递归 Angular 指令,它使用模板变量并在 link 函数中编译。
问题是,我的模板已经变得很长并且无法控制,我想将它外部化到一个外部 HTML 文件中(它也可以更容易地自动缩进)。
如何将外部模板加载到可以在$compile 中使用的指令中?
我见过templateURL,但这不允许我命名变量并将其传递给$compile 函数。
var template =
"<p>My template</p>"+
"<this-directive val='pass-value'></this-directive>";
return {
scope: {
...
},
...
link: function(scope, element){
element.html(template);
$compile(element.contents())(scope);
}
}
和
【问题讨论】:
标签: angularjs templates angularjs-directive external