4

Each time I refresh my page, the data in AngularJS variables is lost. How to retain them without using cookies? Can anyone help me with an approach? Its different from the previous question because I am interested in a solution that does not use cookies.

Community
  • 1
  • 1
Nickal
  • 669
  • 2
  • 11
  • 25

3 Answers3

3

For amounts of data less than 4k you can use $cookieStore. If it is more than that you'll need to look into HTML5 localStorage

For more details please go through this post you will find different options of storage with comparison http://www.html5rocks.com/en/tutorials/offline/storage/

Rahul
  • 367
  • 2
  • 6
  • 27
2

I think that you have only 2 options here:

  1. Use localStorage. There're lots of handy localStorage angularJS modules to use.
  2. If you don't want to store data on the client side, you could request your API for the data you need to store each time your angular app is getting loaded. This data seems to be static, as you are storing it on client side and reuse then, so you could configure API endpoint to throw this data really fast.
xSaber
  • 384
  • 1
  • 11
1

use localStorage.setItem("key",value); to set the value.

use localStorage.getItem("key");to get the value.

use localStorage.clear();to clear the value which is set

Anirudh
  • 558
  • 1
  • 6
  • 22