All applications have a $rootScopethat can function in all of the HTML elements contained in the ng-app directive.
$rootScope can act on the entire application.
is the bridge of scope in each controller.
Values defined with Rootscope can be used in each controller.
Try all kinds of things ....
<body>
<div ng-app= "myApp" >
<ul ng-controller= "Myctrl" >
<li ng-repeat= "x in Names" >{{x}} {{lastname}}</li>
</ul>
<div ng-controller= "MyCtrl2" >
{{LastName}};//can access
{{names}}//cannot be accessed
</div>
</div>
<div ng-app= "app2" ng-controller= "Appctrl" >
{{LastName}}//error cannot be accessed
</div>
<script src= "Myjs/angular.js" ></script>
<script>
var app = Angular.module (' myApp ', []);
app.controller (' Myctrl ', function ($scope, $rootScope) {
$scope. Names = ["Emil", "Tobias", "Linus"];
$rootScope. LastName = "Refsnes";
});
app.controller (' MyCtrl2 ', function ($scope) {
});
var app2 = angular.module (' myApp2 ', []);
app2.controller (' Appctrl ', function ($scope) {
});
</script>
</body>
angularjs-$rootScope