Typescript permanent variable

Hello everyone,
In my project I have a simple counter in a button: when this button is clicked, the counter increments by 1. I need to permanently store this value, and now I’m using “storage.set” (retrieving it in another page with “storage.get”). But the storage works only on one sessione, because when I close and re-open the application, the counter starts again from zero. This is my code:

public counter = 0;


So, the page reloads the public counter instead of using the value stored: how can I declare the variable and then use the one that is saved in the storage? Yes, is a silly and stupid question, but I’m new to the world of coding.

Thanks for your time!

how you define this.storage ?

You can try to use localStorage variable, this is persistent and will be available on next launch


make sure, that you set the initial value of the counter on the app launch:


I don’t believe this is true. iOS in particular may wipe localStorage whenever it feels it needs working space.

Hmm , i wasn’t aware of this, but after some research i can confirm what you are saying… What else do you recommend in this case then?

Use the default Ionic Storage with sqlite plugin.