簡體   English   中英

localstorage.setitem 不以角度工作

[英]localstorage.setitem not working in angular

下面是我的功能。 我可以在 console.log 中看到一個帶有res的對象:

login2(){
    console.log(this.user_form_value);
    console.log(this.password_form_value);
    this._loginService.login(this.user_form_value, this.password_form_value).subscribe(
      res => console.log(res.user),
      res2 =>localStorage.setItem("getLoggedInUserANG1",JSON.stringify(res2.user))
      )

  }

但是當我嘗試在本地存儲中存儲相同的對象時,它沒有被保存。 我是 angular 的新手,但沒有錯誤,我不知道為什么它沒有被保存。

保存后,我還想使用數組變量中的getitem獲取相同的內容, getitem放在 console.log 中。 我想了解基礎知識的問題以及我哪里出錯了。

下面是我的 console.log 的截圖

在此處輸入圖片說明

res2沒有定義。 我相信您需要查看JavaScript Arrow Funcions 文檔

試試看:

login2() {
    console.log(this.user_form_value);
    console.log(this.password_form_value);
    this._loginService.login(this.user_form_value, this.password_form_value).subscribe(
        res => {
            console.log(res.user);
            localStorage.setItem("getLoggedInUserANG1",JSON.stringify(res.user));
        }
    )
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM