The Relationship Between the Root Scope and Applications

When an application is bootstrapped, a root scope is created. The root scope stores data at the application level, and you can access it by using the $rootScope service. The root scope data should be initialized in the run() block of the module, but you can also access it in components of the module. To illustrate this, the following code defines a value at the root scope level and then accesses it in a controller:

angular.module('myApp', [])
.run(function($rootScope) {
    $rootScope.rootValue = 5;
})
.controller('myController', function($scope, $rootScope) {
  $scope.value = 10;
  $scope.difference = function() {
        return $rootScope.rootValue - $scope.value;
    };
});

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.95.203