Hello, everyone, today when building a website with MEAN stack, we created a universal template index.html. After creating < head >, < header > and < footer >, I want to use ng-view and other html files as the main content of the page.
When I was using ng-view to load a main.html on another page, I found that if I put JS code needed by main.html in index.html, the code would have run before main.html was loaded. At the end of main.html, JS will not be loaded due to ng-view’s feature.
The following is the code for index.html:
The following is the code for main.js:
I would like to ask you how you can solve this problem and let JS run successfully when you encounter this situation.
Thank you all!
If the js written by the host will affect this page, you can use lazy loading, a route to load a js file and view. This is what our project is currently using.https://github.com/Vanthink-UED/AngularAMD-Tutorial