# First time local storage value getting null

**URL:** <https://forum.ionicframework.com/t/first-time-local-storage-value-getting-null/129478>\
**Category:** ionic-v3\
**Created:** [May 2, 2018, 6:24am UTC](https://forum.ionicframework.com/t/first-time-local-storage-value-getting-null/129478 "2018-05-02T06:24:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![flycoders\_sourav](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@flycoders\_sourav](https://forum.ionicframework.com/u/flycoders_sourav)\
**Post date:** [May 2, 2018, 6:24am UTC](https://forum.ionicframework.com/t/first-time-local-storage-value-getting-null/129478/1 "2018-05-02T06:24:45Z")

</div>

First time login when i try get local storage value on that time local storage value getting **null** but send time login and try to get local storage value its working file working fine

I’m set the value into the local storage like this

```auto
           this.storage.set('loggedIn', this.loggedIn);
           this.storage.set('username',this.user_name);
           this.storage.set('userid', this.userid);
           this.storage.set('license', this.license);
           this.storage.set('userType', this.userType);

```

And get like this

```auto
ionViewDidLoad() {
          this.storage.get('license').then(lic => {
          alert(this.license =lic)
          });
         this.storage.get('username').then(user => {
          alert(this.gaurdname =user);
         
          });
             this.storage.get('userid').then(id => {
             alert(this.user_id =id)
         
          });   
  }

```

Please any one help me out  
Thanks

---

<div class="post-metadata">

**Author:** ![rohitqa001](https://avatars.discourse-cdn.com/v4/letter/r/f6c823/32.png) [@rohitqa001](https://forum.ionicframework.com/u/rohitqa001)\
**Post date:** [May 2, 2018, 7:44am UTC](https://forum.ionicframework.com/t/first-time-local-storage-value-getting-null/129478/2 "2018-05-02T07:44:48Z")

</div>

I am also facing this issue since last night, before its working properly.  
Give some suggestion if any one have resolved this issue.

Thanks

---

<div class="post-metadata">

**Author:** ![flycoders\_sourav](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@flycoders\_sourav](https://forum.ionicframework.com/u/flycoders_sourav)\
**Post date:** [May 2, 2018, 12:06pm UTC](https://forum.ionicframework.com/t/first-time-local-storage-value-getting-null/129478/3 "2018-05-02T12:06:32Z")

</div>

You can try like this

```auto
constructor(){

	   let self = this;
   setInterval(function () {
    self.getData();
  }, 300);	
}

 getData(){
 this.storage.get('username').then(val => {
          this.username =val;
          }); 
}

```

---

<div class="post-metadata">

**Author:** ![Tommertom](https://avatars.discourse-cdn.com/v4/letter/t/ed8c4c/32.png) [@Tommertom](https://forum.ionicframework.com/u/Tommertom)\
**Post date:** [May 2, 2018, 2:34pm UTC](https://forum.ionicframework.com/t/first-time-local-storage-value-getting-null/129478/4 "2018-05-02T14:34:59Z")

</div>

If u need setTimeout to resolve async nature of storage then u are missing a fundamental point

U need to chain the storage-set promises (or use Promise.all) and after completion set a flag to say all is stored. And use that in thr storage get sonewhere else to see if there is data stored before u get it.

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:37pm UTC](https://forum.ionicframework.com/t/first-time-local-storage-value-getting-null/129478/5 "2021-07-19T21:37:19Z")

</div>

Closed on July 19, 2021, 9:37pm UTC


