Retrieving values and storing them into Typescript variables #21
-
I have coded this example: `
}` Why 'this.myVariable' is 'undefined'? I assigned into this variable the 'myUser.lastName' value. Best regards, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
All operations in this lib are asynchronous, so your code is wrong. You should wait the setter has finished before accessing the value : this.localStorage.setItem('user', user).subscribe(() => {
this.localStorage.getItem<User>('user').subscribe((myUser) => {
// Do something
});
});` The rest is just Angular, please use stackoverflow for any support question. |
Beta Was this translation helpful? Give feedback.
-
I'm experimenting the same problem with storagemap, cant assign subscription response to any variable |
Beta Was this translation helpful? Give feedback.
All operations in this lib are asynchronous, so your code is wrong. You should wait the setter has finished before accessing the value :
The rest is just Angular, please use stackoverflow for any support question.