Web development blog for Html, CSS, javascript, JQuery developers. At Kodecrash you will find best solution for complex problems.

$rootScope in Angular JS

Posted in Angular JS

rootscope
$rootScope refers to an object which is accessible from everywhere of the application. You can think $rootScope as global variable¬†which can be accessible in all controllers, services, directives. The $rootScope object has a function called $new() that’s used to create child scopes.

Angular JS finds ng-app and therefore creates a $rootScope object. Next, while traversing the DOM, Angular JS encounters another ng-controller directive which points to “myController”. Now, it creates another child scope using $rootScope.$new() called $scope.

Injecting rootScope in a controller:
rootscope