$rootScope
$rootScope declare any one controller it will allow to accessing all controller no any restriction for implement. Will include the $rootScope directive from the controller library loader time.
Sample $rootScope Declaration
var app = angular.module('rootModule',[]);
app.controller('firstController',['$scope','$rootScope',function($scope, $rootScope){
console.log('first');
}]);
Program Example
Html:
<div ng-app="rootModule">
<div ng-controller="firstController">
Click count : {{count}}
<input type="button" value="click" ng-click="countCal()" />
</div>
<div ng-controller="secondController">
Click Count : {{count}}
<input type="button" value="click" ng-click="countCal()" />
</div>
<div ng-controller="thirdController">
Click Count : {{count}}
<input type="button" value="click" ng-click="countCal()" />
</div>
</div>
JavaScript :
var app = angular.module('rootModule',[]);
app.controller('firstController',['$scope','$rootScope',function($scope, $rootScope){
console.log('first');
}]);
app.controller('secondController',['$scope','$rootScope',function($scope, $rootScope){
console.log('scrond');
}]);
app.controller('thirdController',['$scope','$rootScope',function($scope, $rootScope){
$rootScope.count = 0;
$rootScope.countCal = function(){
$rootScope.count = $rootScope.count + 1;
}
}]);
Result :
Comments
Post a Comment