Using external Javascript files inside an Angular directive template

瘦欲@ 提交于 2019-12-23 17:01:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!