在sessionStorage中将数据保存为未定义的角度 [英] Saving data in sessionStorage as undefined in angular

查看:38
本文介绍了在sessionStorage中将数据保存为未定义的角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将地址数据保存在sessionstorage中,但是它显示未定义的位置,其他数据保存得很好,并且也无法检索数据.有人可以在这里提出问题吗

Im saving the address data in the sessionstorage but it shows undefined where other data are saving fine and im able to retrive the data also.can anyone suggest what is the problem here

helper service
 /**ENCRYPT the value */
  encryptValue(data: string) {
    if (data)
      return CryptoJS.AES.encrypt(data.trim(), environment.ENC_SECRET_KEY.trim());
  }

  /**DECRYPT the value */
  decryptValue(data: string) {
    if (data)
      return CryptoJS.AES.decrypt(data.trim(), environment.ENC_SECRET_KEY.trim()).toString(CryptoJS.enc.Utf8)
  }

login component
 /** store user INFO **/
  private _storeUserInfo(data) {
    sessionStorage.setItem("token", this.helper.encryptValue(data["access_token"].trim()));
    sessionStorage.setItem("mm-eml", this.helper.encryptValue(data["email"].trim()));
    sessionStorage.setItem("id", this.helper.encryptValue(data["id"]));
    sessionStorage.setItem("username", this.helper.encryptValue(data["username"]));
    sessionStorage.setItem("tenant_id", this.helper.encryptValue(data["tenant"]));
    sessionStorage.setItem("address",this.helper.encryptValue(data["address"]));
  }

im在另一个模块中调用它

im calling it in the another module

helper service

  /** DECRYPT the email */
  getEmail() {
    if (sessionStorage.getItem('mm-eml')) {
      return this.decryptValue(sessionStorage.getItem('mm-eml').trim());
    } else {
      return null;
    }
  };

  /** DECRYPT the user-id */
  getUserId() {
    if (sessionStorage.getItem('id')) {
      return this.decryptValue(sessionStorage.getItem('id'));
    } else {
      return null;
    }
  };

    /** DECRYPT the user-id */
    getUserName() {
      if (sessionStorage.getItem('username')) {
        return this.decryptValue(sessionStorage.getItem('username'));
      } else {
        return null;
      }
    };

  /** DECRYPT the tenant-id */
  getTenantId() {
    if (sessionStorage.getItem('tenant_id')) {
      return this.decryptValue(sessionStorage.getItem('tenant_id'));
    } else {
      return null;
    }
  };
 /** DECRYPT the location-address */
 getLocationAddress() {
  if (sessionStorage.getItem('address')) {
    return this.decryptValue(sessionStorage.getItem('address'));
  } else {
    return null;
  }
};

一切正常,除了在会话存储中显示未定义的地址

everything is fine except the address which shows undefined in session storage

推荐答案

我得到了解决方案,在该解决方案中,我没有正确地将数据绑定到会话存储中.

i got the solution, where i didnt properly bind the data to store in the session storage.

这篇关于在sessionStorage中将数据保存为未定义的角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆