问题
I am loading dinamically in my webapp "components", which has a directive, and a template, like the following:
angular.module('app')
.directive('carousel', function() {
return {
restrict: 'E',
scope: {
left: '@',
top: '@'
},
templateUrl: 'carousel.html'
};
});
This template can have CSS dependencies, and it will work, but it won't work with Javascript. How do you think it could work?
Template example (carousel.html)
<link rel="stylesheet" type="text/css" href="example.css" media="all"> //This works
<script src="jquery.min.js"></script> //This don't work. It doesn't even request the file to the server.
<script>
alert('This alert is not executed');
function alertFn(){
alert('This alert is not executed even calling the function from other parts of the code');
}
</script>
<p class="templateExample">This template paragraph is loaded correctly in the view</p>
回答1:
At the end the problem was solved using jquery as a main dependency.
Empirically I can see that when you use the Javascript files and scripts from the templates is effectively loaded.
来源:https://stackoverflow.com/questions/24656983/using-external-javascript-files-inside-an-angular-directive-template