Giter Site home page Giter Site logo

Comments (10)

paulovitorjp avatar paulovitorjp commented on August 22, 2024 1

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!

from ionic-storage.

jgw96 avatar jgw96 commented on August 22, 2024

Hello, thanks for using Ionic! It seems that this issue is most likely caused by your use of new with storage and by putting storage in your imports array. Could you take a look at the docs for ionic storage and give it another try? Thanks!

from ionic-storage.

jgw96 avatar jgw96 commented on August 22, 2024

From @jherediagu on November 1, 2016 11:27

Yes, it's lost data, I have the same problem, I solve it with localforage, like this:

import localforage from 'localforage';

   localforage.setItem<any>('foo', 'bar');

   localforage.getItem<any>('foo').then( (value:any) => {
      console.log(value);
   });

from ionic-storage.

jgw96 avatar jgw96 commented on August 22, 2024

Thanks for the info. Unfortunately I cannot reproduce this issue, would you posting a repo or a zip of your project that I can use to reproduce this issue?

from ionic-storage.

tabirkeland avatar tabirkeland commented on August 22, 2024

I was seeing similar behavior and then wrapped my storage method calls in platform.ready().then(() => { });.

Solved my problems.

from ionic-storage.

mirkonasato avatar mirkonasato commented on August 22, 2024

Could be the same issue as #20

from ionic-storage.

FdezRomero avatar FdezRomero commented on August 22, 2024

@jgw96 I'm having the same problem on Android with the latest versions, whereas 1.0.x were working okay. I checked just in case and I'm not using new nor have Storage in my app module imports.

I agree that it seems related to #20, as I noticed to have keys in localstorage and Storage should always pick SQLite as the engine (I have the plugin installed).

Thanks!

from ionic-storage.

mirkonasato avatar mirkonasato commented on August 22, 2024

I submitted PR 19 weeks ago as a possible fix for these issues. Would be nice if somebody could look at it.

from ionic-storage.

 avatar commented on August 22, 2024

I faced the same issue and found a workaround. Reading above comments, i came to conclusion that rootpage should not be set until platform loads. I initialised the rootPage inside platform.ready().
The code looks like this:

export class App {
. . .
rootPage;

  constructor(private storage: Storage, public platform: Platform) {
      this.platform.ready().then(() => {
        this.rootPage = ||your login page||;
        StatusBar.styleDefault();
        Splashscreen.hide();
      });
  }
. . .

This works for me, hope it helps all. Do try and share your experience and thoughts.

from ionic-storage.

mlynch avatar mlynch commented on August 22, 2024

Fixed with #21

from ionic-storage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.