简体   繁体   English

在 LocalStorage.getItem 中将值作为“空”值获取

[英]getting the values as 'null' value in LocalStorage.getItem

In my application I have to use the Email value coming from login to dashboard component(both are individual components).在我的应用程序中,我必须使用来自登录到仪表板组件的 Email 值(两者都是单独的组件)。

So in login component I have stored the values in localstorage by using setItem as'因此,在登录组件中,我使用 setItem 将值存储在 localstorage 中

login.component.ts登录组件.ts

//somecode

 if (loggedIn) {
         
         
          localStorage.setItem(LocalStorageKey.KEY_CoachGender, this.coachProfile.CoachGender);
          localStorage.setItem(LocalStorageKey.KEY_Email, this.coachProfile.Email);
}

and 
**Dashboard.component.ts**

 let EmailId = localStorage.getItem(LocalStorageKey.KEY_Email);

  this.hubConnection.invoke("Register", EmailId)
  console.log("Connected")
  console.log(EmailId)

But while I am getting the EmailId from loacal Storage I am getting the null value in console Can anyone help me how to get the value without getting the nullvalue但是,当我从本地存储中获取 EmailId 时,我在控制台中获取了 null 值 谁能帮助我如何在不获取空值的情况下获取值

I believe that problem is you don't have considered the asynchronicity, probability you don't wait the logging is done before you insert the result in localStorage我相信问题是您没有考虑异步性,您可能没有等待日志记录完成,然后再将结果插入 localStorage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM