ionic storage getting values in Aync way

半世苍凉 提交于 2019-12-01 14:02:46
Rohit Gupta

You have to wait for both promise to get resolved before make request. First move your storage code to some init method.

public init(){

let promiseList: Promise<any>[] = [];
promiseList.push(
 this.storage.get('Auth').then((Auth) => {
      console.log('Retrived Auth is', Auth);
      this.Auth = Auth;

    } ));
promiseList.push(
    this.storage.get('url').then((url) => {
      console.log('Retrived url is', url);
      this.url = url;
    } ));

return Promise.all(promiseList);
}

Now call init method before getSesonList as followed:

this.sessionService.init().then((values)=>{
this.sessionService.getSeasonList();
});

this will make sure that the getSeasonList method will be called after both storage promises get resolved.

Obviously you should put some error handling code but its upon you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!