I have some variables in angular controller. I have there if user is logged in and other details . When i am refreshing my page using f5 all my variables are reloading and i am getting in log in page, but before refresh i was already logged in and my variable isUserLoggedIn was true but after refresh it is false , false is this variables default value, I am declaring it in Controller .How can I save all my variables ( current point of angular controller ) and continue with my saved point after refresh ?
1 Answer
You can use the browsers local storage(HTML5) and store your data.
E.g: to write:
$window.localStorage['sample-key'] = 'sample-data;
to read:
var data = $window.localStorage['sample-key']
There are many libraries available for this, you can check this one: https://github.com/grevory/angular-local-storage
4 Comments
Sachin Gupta
you don't need to catch refresh event, as it is stored in browser itself.
Sachin Gupta
I think you should first take a look at local storage, how it works. then I think it would be good for you to use it.
localstoragelike @Sachin Gupta said too, how can i catch refresh event to restore my variables from thislocalstorage?