0

I have following problem: in my app based on Ionic Framework I have something like authentication: I log in and after that store token in a service.

But what is a proper way to store variables? I could use services, localStorage, (something else)?

For example, after login I want to show a list and depending on choice (on an id from a list) show something in details tab, but still have an ability to move for example to account tab, or other tab and still have an information on selected choice (like, clicking on details tab still would show previously selected item).

So how for example store such a variable?

I hope I didn't mess the explanation of my problem too much.

Thanks :)

user3857967
  • 3
  • 1
  • 2
  • Do you want to store variables for the current session only or you want to keep the values even if the app is stopped?? – AtanuCSE Jul 20 '14 at 13:52
  • Thank you for your comment. For now I would need to store variables only when app is alive, not after restart. – user3857967 Jul 20 '14 at 14:16
  • You should check the ionic forums before posting a question here; this question has been asked am answered multiple times there – Aaron Saunders Jul 20 '14 at 23:02

1 Answers1

1

You can use localStorage. It's pretty good for this kind of little things.

localStorage.setItem("storage_name","something");
var another_variable=localStorage.getItem("storage_name");

And if you need the values even after restarting the app, then you will need something like webSql, specially for iOS

AtanuCSE
  • 8,832
  • 14
  • 74
  • 112
  • 3
    localStorage is persistent even if you close the app. – Andrew McGivery Jul 21 '14 at 18:02
  • 1
    AFAIK not in iOS. iOS consider localStorage as temporary @AndrewMcGivery – AtanuCSE Jul 21 '14 at 18:43
  • 2
    localStorage, by definition, is persistent, and I have tested this in apps that I have created. I just tested it now on a device. sessionStorage, is not persistent, but localStorage is. – Andrew McGivery Jul 21 '14 at 18:48
  • I have read somewhere that iOS treat localStorage as temporary. It'll wipe out the localStorage if it needs that memory. @AndrewMcGivery – AtanuCSE Jul 21 '14 at 19:02
  • 1
    >Starting from IOS 5.1 Apple decided to make local storage a temp area. http://stackoverflow.com/questions/15923296/localstorage-cleared-after-restarting-the-application-on-phonegap-ios @AndrewMcGivery – AtanuCSE Jul 21 '14 at 19:03
  • 2
    I stand corrected, however if you read this thread, PhoneGap 3.0 fixes this issue, so it works as expected. http://stackoverflow.com/questions/9664392/phonegap-ios-5-1-and-localstorage – Andrew McGivery Jul 21 '14 at 19:10