I've got a recursive Angular directive that uses a template variable and gets compiled in the link
function.
Problem is, that my template has gotten really long and out of control and I want to externalize it in an external HTML file (it would also make it easier for example to auto-indent).
How can you load an external template into a directive that can be used inside the $compile
?
I've seen templateURL
, but that doesn't let me name the variable and pass it to the $compile
function.
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);
}
}
and