我有一个递归的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);
}
}
Run Code Online (Sandbox Code Playgroud)
和