Skip to content

$rootScope in Angular JS

$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:

Published inAngular JS

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *