[英]localstorage.setitem not working in angular
Here is my function below.下面是我的功能。 I can see an object in the console.log with
res
:我可以在 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))
)
}
But when I try to store the same object in the local storage, it's not being saved.但是当我尝试在本地存储中存储相同的对象时,它没有被保存。 I'm new to angular but there isn't a bug and I don't know why it isn't not being saved.
我是 angular 的新手,但没有错误,我不知道为什么它没有被保存。
After saving it I would also want to fetch the same one using getitem
in an array variable and have it console.log.保存后,我还想使用数组变量中的
getitem
获取相同的内容, getitem
放在 console.log 中。 I would like to understand the problem with the basics and where precisely I'm going wrong.我想了解基础知识的问题以及我哪里出错了。
Below is the screenshot of my console.log下面是我的 console.log 的截图
res2
is not defined. res2
没有定义。 I believe that you need take a look at JavaScript Arrow Funcions docs .我相信您需要查看JavaScript Arrow Funcions 文档。
Try it:试试看:
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.