I am trying to retrieve my template for a directive using a repository I have built that returns a promise that resolves to the contents of the template.
What is the difference between using the compile function in a directive and using the $compile service in the link function?
Compile Function
compile: function (element, attrs) {
templateRepository.get('Shared/Login').then(function (result) {
element.replaceWith(result);
});
}
This renders the HTML, but the scope is not bound to the DOM elements.
Using $compile
link: function (scope, elem, attrs) {
templateRepository.get('Shared/Login').then(function (result) {
elem.html(result);
$compile(elem.contents())(scope);
});
}
This works as expected.
What is the difference here?