How can I include a template URL inside link function in a directive? I am trying to do something like this:
app.directive('something', function($compile,$timeout) {
return: {
link: function(scope,element,attrs) {
var htmlText = ???? // HOW TO INCLUDE A TEMPLATE URL HERE??
$compile(htmlText)(scope, function(_element,_scope) {
element.replaceWith(_element);
});
},
}
});
When I searched, I understand that Angular directives can use templateUrl
. But I am trying to store the html codes to a variable that is placed inside the link
which in the end gets compiled. Usually for small codes, I just type the HTML inline to var htmlText
. But if I have a lot of code, I want to save that to a separate html file and then call that for that variable (like its shown in example above). So my questions are
1) How can I add a link to template URL for a variable inside link
?
2) When I am adding the url path, do I add the relative path from where the index.html file is located or the path from where that directive file is located?