Looking for help with assigning an Ionic2 Storage value to a local variable. When I console.log inside the .then, it works fine, but the value seems to be limited to that function/method only. Most examples I've found demonstrate how to 'get' the data, but don't really show how to apply it to other parts of my code.
-appreciate any assistance
import { Storage } from '@ionic/storage';
export class MyApp {
favDessertMax: string;
favDessertRuby: string;
constructor(storage: Storage) { }
storage.ready().then(() => {
this.storage.set('Max', 'Apple sauce');
this.storage.set('Ruby', 'Banana split');
Promise.all([
this.storage.get('Max'),
this.storage.get('Ruby'),
])
.then(([val1,val2]) => {
this.favDessertMax = val1;
this.favDessertRuby = val1;
console.log(val1 + " " + val2); //values are accessible here
})
console.log(val1 + " " + val2); // values are not accessible outside of the function (or anywhere else)
});
storyTime() { // Need value to work here
let myStory = 'Max likes ' + this.favDessertMax + ' and Ruby Likes 'this.favDessertRuby';
return myStory;
}
}