Ionic 2 Local Storage Unable To Set Retrieved Value To Variable
I am trying to set the value retrieved from .get function into a variable declared outside but unable to do so. var dt; //retrieve this.local.get('didTutorial').then((value) =>
Solution 1:
Reading from your localStorage wrapper in this case is asynchronous, which means that the callback passed to this.local.get
gets called after your call to console.log
. Try placing console.log
inside your callback; it should work then:
// retrievethis.local.get('didTutorial').then((value) => {
alert(value)
var dt = value
console.log("Local Storage value:", dt)
})
Also, you'll notice that I changed your console.log
call arguments. That's because console.log
accepts 1 or more parameters, and formats them much more nicely when you pass them in instead of concatenating them. Just a pro tip.
Post a Comment for "Ionic 2 Local Storage Unable To Set Retrieved Value To Variable"