Skip to content

Retrieving values and storing them into Typescript variables #21

Answered by cyrilletuzi
abelardolg asked this question in Q&A
Discussion options

You must be logged in to vote

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.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by cyrilletuzi
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #21 on December 08, 2020 21:34.