AngularJS globle scope

by manoj

HTML

<script src="http://code.angularjs.org/angular-1.0.0rc5.min.js"></script>
<!doctype html>
<html ng-app="myApp">
<body>
<div ng-controller="DemoController1">
    {{clientId.value}} <input ng-model="clientId.value"/> <button type="button" ng-click="change()">Change</button>
    </div>
    <div ng-controller="DemoController2">
        {{clientId.value}} <input ng-model="clientId.value"/> <button type="button" ng-click="change()">Change</button>
    </div>
</body>
</html>

JavaScript

angular.module('components', [])
.value('clientId', { value: 'a12345654321x'} )
    .controller('DemoController1', ['$scope', 'clientId', function ($scope, clientId) {
        $scope.clientId = clientId;
        $scope.change = function() {
            clientId.value = 'yyy';
        }
}])    .controller('DemoController2', ['$scope', 'clientId', function ($scope, clientId) {
        $scope.clientId = clientId;
        $scope.change = function() {
            clientId.value = 'xxx';
        };
}]);
angular.module('myApp', ['components'])