[英]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.