1

I am using ng-include to call the header content and the footer, like this :

<div ng-app="app">
    <div ng-include="'pages/header.html'"></div>
    <script src="js/Listenrs.js"></script>
    <!-- more content -->
</div>

I have a native js file with event listeners that is in the js folder, without the ng-include all the listeners are working but when using ng-include all the event listeners are ignored, a check alert inside the script shows the browser did not ignore the file but besides the alert the listeners dont work.

Maen
  • 10,603
  • 3
  • 45
  • 71
sags
  • 11
  • 4
  • 1
    Please share the code to have the better understanding of it. – Shashank Feb 04 '16 at 11:12
  • Possible duplicate of [AngularJS: How to make angular load script inside ng-include?](http://stackoverflow.com/questions/12197880/angularjs-how-to-make-angular-load-script-inside-ng-include) – Grundy Feb 04 '16 at 11:38
  • use **defer** like: I think your JS file load before Template – Sandeep Feb 04 '16 at 12:02
  • I changed the structure of the js file that handles the event listeners, to call in the function directly without checking readystate change and that works fine. Inside of the header and the footer I placed the script src call to the different js files and it works fine. So no need to call them via the angular controller – sags Feb 05 '16 at 13:05

1 Answers1

0

You should include JQuery library before AngularJS library in your index file for any lazy-loaded scripts to be compiled and added to the JS namespace automatically. Please look at the following code.

[index.html]

<head>
   <script src=jquery.js>
   <script src=angular.js>
</head>

<body>
   <ng-include src="templateurl"></ng-include>
</body>

[template.html]

<head>
   <script> 
      alert(" script loaded")
   </script>
</head>

You will get the alert in the above configuration.

Charlie
  • 22,886
  • 11
  • 59
  • 90
  • Thanks I tried that but its not the problem. If I put an alert inside the functions it shows them, but it does not generate the html content specified in the functions – sags Feb 04 '16 at 11:32
  • Please share your code. Did you put the alert statement inside the function and see what happens? – Charlie Feb 04 '16 at 11:34