1
ローカル変数にIonic2 Storage.getの値を割り当てる方法を知っている人はいますか? .then内のconsole.logがうまくいけば、それはその関数/メソッド内にしか存在しないようです。私は、見る私のデータが、ノー本当に私の他のコードに適用Ionic2 Storage Promise.allスコープ
-thanks
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 work here
})
console.log(val1 + " " + val2); // values don't work out here (or anywhere else)
});
storyTime() { // Need value to work here
let myStory = 'Max likes ' + this.favDessertMax + ' and Ruby Likes 'this.favDessertRuby';
return myStory;
}
}