I had problems with my localforage, where localforage can't set a global variable in the success callback but when i console.log
display showing values.
Localforage data:
Key: login
Value: [{"token": "bla bla bla", "member_id":1}]
Code
public login_data: any;
getMemberData() {
localforage.getItem("login").then(function(value){
this.login_data = value[0];
});
console.log(this.login_data);
}
Output
undefined
All I want is to make it into a global variable. And I can use it easily, such as:
this.login_data.member_id
or
this.login_data.token
Some ways I have tried not correspond to my expectations. i have tried:
Assign value from successful promise resolve to external variable
how to assign the returned value of a promise to a variable?
setting a variable to get return from call back function using promise
Assign value from then function to a variable promise
[Note] I use Ionic 2, AngularJS 2, LocalForage
thanks