Angular: Goble scoped varible

http://angularjs.org/

by manoj

HTML

<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-app="myApp">
    {{name}}
<div ng-controller="MyCtrl1">
  I just set the global variable.
</div>
<div ng-controller="MyCtrl2">
  Hello, {{name2}}!
</div>
</div>

JavaScript

var myApp = angular.module('myApp',[]);
function MyCtrl1($scope, $rootScope) {
    $rootScope.name = 'anonymous'; 
}

function MyCtrl2($scope, $rootScope) {
    $scope.name2 = $rootScope.name; 
}