Where is rootScope
values are stored? In cookie or local storage?
I have a small doubt about rootScope
in angularjs
.
I have passing a value between two controllers, So I have using the
$rootScope
.
I want to know how to
rootScope
Working? and where is therootScope
data stored?In
Local Storage
orcookie
or anything else?
When switching controllers (or routes or states) in AngularJS only what's inside the controller closure is destroyed, anything outside of it is not.
$rootScope
is a service instantiated only once on the page so when you switch controllers it is not destroyed. That's why it's persistent. If you reload the whole page (hit [F5] in your browser) then everything in it is lost.This is something fundamental for the whole Single Page Application pattern.
If you look into the sources for this service you won't find anything related to cross-page persistence.