In following example there are three modules, first one is required by second module. And this works when referenced using ng-app
in div
. But third module that goes by the name of someonesApp
does not work. It's run method is not run when second module is being referenced using ng-app. Without first two modules third one works, why is that so?
<!DOCTYPE html>
<html >
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script>
</head>
<body ng-init="name='123'">
<div ng-app="myApp">
</div>
<div ng-app="someonesApp">
</div>
<script>
var yourApp = angular.module('yourApp',[]);
yourApp.run(function(){
console.log('run block of yourApp');
});
var myApp = angular.module('myApp',['yourApp']);
myApp.run(function(){
console.log('run block of myApp');
});
var someonesApp = angular.module('someonesApp',[]);
someonesApp.run(function(){
console.log('run block of someonesApp');
});
</script>
</body>
</html>
Here is modified code, in this case I removed <div ng-app="myApp"></div>
and third module works.
<!DOCTYPE html>
<html >
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script>
</head>
<body ng-init="name='123'">
<div ng-app="someonesApp">
</div>
<script>
var yourApp = angular.module('yourApp',[]);
yourApp.run(function(){
console.log('run block of yourApp');
});
var myApp = angular.module('myApp',['yourApp']);
myApp.run(function(){
console.log('run block of myApp');
});
var someonesApp = angular.module('someonesApp',[]);
someonesApp.run(function(){
console.log('run block of someonesApp');
});
</script>
</body>
</html>