Storage get value


#1

Hi,
it’s OK.

		this.storage.get('buttonBool').then((data)=>{this.flag=data;});
		this.storage.get('buttonBool').then((data)=>{console.log(this.flag);});

But

		this.storage.get('buttonBool').then((data)=>{this.flag=data;});
		console.log(this.flag);

why undefined value?
How do I use it?


#2

#3
	storageGet(){
		Promise.all([
		this.storage.get('name').then((data)=>{this.var=data;}),})]);
		console.log(this.var.toString());
	}


ı’m using above
but same thing


#4

Same problem: The Promises only resolve after console.log already executed. You have to use .then for Promise.all so the console.log only gets executed after all the inner Promises resolved.


#5

Ok.but I use different function this.attribute undefined

	ionViewDidLoad(){
		this.storageGet();;}

#6

Same problem: You execute stuff in this.storageGet async, then execute console.log directly while it is not yet finished. You have to return the promise in storageGet you get from Promise.all and use then() on storageGet.


#7

such is?

ionViewWillEnter(){
    Promise.all([]).then(()=>this.storageGet());
 
}

  storageGet(){
    this.storage.get('name').then((data)=>{this.var=data;});
}

#8

i think it should be

var promise1= this.local.get('id');
var promise2 = this.local.get('name');

Promise.all([promise1, promise2 ]).then((arrayOfResults) => {
console.log(arrayOfResults[0]);
console.log(arrayOfResults[1]);
});

#9

storageGet function console write
but ionViewWillEnter console not write

  ionViewWillEnter(){
    this.storageGet();;}

storageGet(){
    var x0=this.storage.get('name');


  Promise.all([x0]).then((arrayOfResults) => {
    this.var=arrayOfResults[0]; console.log(arrayOfResults[0]);
  });

#10

As I said in the thread that @auspicious linked to earlier, I think your code would be more performant as well as far easier to read, write, and maintain, if you would just combine all of these properties into a single JSON interface instead of storing them all separately.