1,js Code
The code is as follows |
|
Phonecatapp.controller (' Testctrl ', [' $scope ', ' $rootScope ', function ($scope, $rootScope) { $rootScope. Name = ' This is test '; } ]); Phonecatapp.controller (' Test111ctrl ', [' $scope ', ' $rootScope ', function ($scope, $rootScope) { $scope. Name = $rootScope. Name; } ]); |
2,html Code
The code is as follows |
|
<div ng-controller= "Testctrl" > Iset the global variable.<strong>{{$root .name}}</strong> </div> <div ng-controller= "Test111ctrl" > 1,get global variable .<strong>{{name}}</strong><br> 2,get global variable. <strong>{{$root .name}}</strong> </div>www.111cn.net |
3, Show results
The code is as follows |
|
I set the global variable.this is test 1,get global variable. This is test 2,get global variable. This is test |
As you can see from the results, $rootScope. Name set variables, in all controller can be directly with the {{$root. Name}} to display, very powerful. That, of course, can also be assigned a value to scope.