I have a js file in my partial view. How would I load it dynamically when that partial is loaded?
My directory structure is
app
---css
------style.css
----js
-------app.js
-------appRotes.js
-------script.js
----views
-------home.html
-------about.html
----index.html
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script>
<body ng-app="myapp">
<p><a href="#/">Main</a></p>
<a href="#about">Red</a>
<div ng-view></div>
<script src="js/app.js"></script>
<script src="js/appRoutes.js"></script>
</body>
</html>
My app.js
angular.module("myapp", ["myapp.routes"]);
My appRoutes.js
angular.module("myapp.routes",["ngRoute"]).
config(function($routeProvider, $locationProvider){
$routeProvider.
when("/",{
templateUrl : "views/home.html"
})
.otherwise({
redirectTo: '/'
})
.when("/b",{
templateUrl : "views/about.html"
})
.otherwise({
redirectTo: '/'
});
});
My about.html
<h1>About</h1>
<script src="script.js"></script>