Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refreshing an AngularJS and keeping scope variables

Is it possible to keep variables on scope after refreshing my AngularJS page? How do I get this configured?

Thanks!

like image 660
Okcerk Avatar asked Jul 16 '14 19:07

Okcerk


2 Answers

There are several options to do this,

  1. For smaller data you could use the $cookieStore, for data that is under 4k
  2. Another option, especially with large data sets, would be to use Local Storage and then retrieve the data on page load/reload.
  3. if it is only a very small amount of data, or data that is used through out multiple page you could use $rootscope, but this is not the best option as it just like polluting the global name space.
  4. The last option, depending on how the data is retrieved, a service could be implemented, that is basiclly a singlton that can be passed to various angular scope.

All of this is dependent on the data in which you want to store. If you provide more info on what you are trying to achieve then the options could be narrowed.

like image 84
Jared Reeves Avatar answered Nov 03 '22 00:11

Jared Reeves


I realize this is an old Question / Answer but after running into page refresh $scope and a multi-step form issues, I wanted to post what I found to assist. @Jared Reeves is correct above, but I think gsklee ngStroage is a fantastic tool for the question's requirements.

like image 36
Fergus Avatar answered Nov 03 '22 01:11

Fergus