angularjs-$rootScope

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.