I want to add dependencies after AngularJS is bootstrapped. I tried to do it via app.requires.push('app.main');
as suggested in this post (re-open and add dependencies to an already bootstrapped application). However, it does not work.
Here's my example code:
index.html
<!DOCTYPE html>
<html ng-app="app">
<head>
<link rel="stylesheet" href="style.css">
<script type="text/javascript" src="https://code.angularjs.org/1.4.3/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<h1>Hello Plunker!</h1>
</body>
</html>
script.js
var app = angular
.module('app',[])
.run(function($http){
$http.get("script2.js").success(function(data){
eval(data);
//app.requires.push('app.main');
}).error(function(){
alert("error");
});
});
script2.js
alert("it's loaded");
angular.module('app.main', [])
.run(function(){
alert("it's running");
});
console.log(app);
app.requires.push('app.main');
http://plnkr.co/edit/gN2kkoyqamB4OANXMUjA
Why is it doesn't work? How can I fix it?
it's running
alert box. – Shiny