question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Storage from @ionic/storage loses data

See original GitHub issue

From @Lafaa on October 30, 2016 16:29

Hi guys! Am i the only one having problem with the new Storage since the ionic2 rc0?

It just forgets everything once the app is restarted. I use the Storage class from @ionic/storage to save username and password, but it’s like it get cleaned on app restart.

I’m using the Storage this way:

 public storage: Storage;
...
this.storage = new Storage();
...
this.storage.set(key, value);

I’ve also added the Storage in app.module.ts, both in the import section AND in the providers array. Did i get something wrong? In the running and building process i don’t have any error or warnings

Cordova CLI: 6.3.1 Ionic Framework Version: 2.0.0-rc.0-201610131811 Ionic CLI Version: 2.1.0 Ionic App Lib Version: 2.1.0-beta.1 OS: Node Version: v6.7.0

Copied from original issue: driftyco/ionic#8959

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
paulovitorjpcommented, Nov 27, 2016

I am wrapping everything inside platform.ready() as you can see below, and the get returns null everytime.

  constructor(platform: Platform, public deploy: Deploy,public modalCtrl: ModalController, public authSrvc: AuthService,
    public localStorage:Storage, public chatSrvc:ChatService, public prefSrvc:PrefService) {
    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      StatusBar.styleDefault();
      console.log('[App Component] SQLite length: ');
      localStorage.length().then((n)=>{console.log('[App Component] SQLite length: ' + n);});
      localStorage.set('test',true).then(()=>{
        localStorage.get('test').then((test)=>{
          console.log('testing of sqlite was ' + test); //this is always null, even though I just set it to true.
          //...
        });
      });
    });
  }

I’ve seen that @mirkonasato has submitted a pull request for this here #21 . Please @jgw96, could you take a look?

I am using ionic 2.1.8, cordova 6.3.1, ionic storage 1.1.6 and cordova-sqlite-storage 1.5.0.

Thanks!

0reactions
mlynchcommented, Dec 15, 2016

Fixed with #21

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data lost when using ionic/storage
I'm using import { Storage } from '@ionic/storage'; to make iOS app. Some users report their data is lost after a few days...
Read more >
Data lost when using ionic/storage - Angular - TBRG Discourse
I was using “@ionic/Storage” for saving many metadatas in the POS application. In some cases there were issues where the data is missing ......
Read more >
Storing mobile apps data to avoid data loss - Stack Overflow
Currently, it stores data in local storage (ionic storage) and when everything is filled it stores data to MongoDB. but some users have...
Read more >
Choosing the Right Data Storage Solution - Ionic.io
Explore Ionic data storage options: Ionic Storage, Capacitor Storage, plain SQLite storage, and Ionic's Secure Storage solution.
Read more >
Ionic 4 - Save and Retrieve Data Locally on Device - Enappd
Storage is an easy way to store key/value pairs and JSON objects. Storage uses a variety of storage engines underneath, picking the best...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found