Ionic storage.get show nothing

Nothing show in tabIndex

constructor(public storage: Storage) {
      this.storage.get('tabIndex').then((val) => {
        this.tabIndex = val;
      })
      console.log(this.tabIndex); // its return null 
    }

Have you tried to log your ‘val’ as below, to see if it carries any data?

this.storage.get('tabIndex').then((val) => {
        console.log(val);
      })

ya it was working and its carries data. but when I want to use tabIndex variable not showing anything

And like that ? :

constructor(public storage: Storage) {
      this.storage.get('tabIndex').then((val) => {
        this.tabIndex = val;
       console.log(this.tabIndex); // its return null 
      })
     
    }

yes showing :frowning:

If fix your issue. then please mark the solution
Thanks

1 Like

It’s because you call console.log before the get function got the value(.then mean promise so waiting to be resolved), so you have to put in in the promise to be sure that the promise is resolved when you execute the log function.