Javascript can't run with dynamic views loaded

2019-04-17 08:30发布

问题:

I have a problem when I try to load template into ui-view using ui-router. The javascript is loaded but not running on loaded views. The full story is that: I have a template in HTML with full js, css... files. Everything runs perfectly in HTML. Then I add AngularJS with UI-Router to make the page dynamic with view. My code looks like:

<head>
<script src="angular.js"></script>
<script src="angular-ui-router.min.js"></script>
</head>
<body>
 <h1>This is the content of dynamic view</h1>
<div ui-view></div>

<script src="jquery.min.js"></script>
<script src="jqueryui.min.js"></script>
... 
<script src="isotype.min.js"></script>
</body>

When I load the view from ui-router, the layout is correct. But no javascript effects are running. How can I fix that? I want to load a list of js files in the index.html so that when it change the ui-view, i don't have to load them again.

回答1:

I have found the way to fix this problem. The file custom.js which I config every elements in the html template, will be put in the HTML template file. When the index file loads the HTML template, it will load the custom.js file also.