I am trying to get my template for a directive using the repository I created that returns a promise that resolves the contents of the template.
What is the difference between using a function compilein a directive and using a service $compilein a function link?
Compilation function
compile: function (element, attrs) {
templateRepository.get('Shared/Login').then(function (result) {
element.replaceWith(result);
});
}
This displays HTML, but the scope is not bound to 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?
source
share