Reputation: 1303
I need to wait for the localStorage to retrieve a value before continuing my function... I read that I have to use "async/await" instructions but none of the examples I found really works.
My Code is
_ajustes.EsPrimeraVez().then (async (promAjuste)=> {
await console.log('TEST! en el then');
});
console.log('TEST! Post');
and inside "ajustes":
public EsPrimeraVez() {
console.log('TEST! entrando en primeravez');
return this.storage.get('primeravez');
but it doesn't wait to the result to continue... is this possible? Thanks and happy new year to all!
Upvotes: 0
Views: 795
Reputation: 208
Why are you using prmoise/then syntac if you want to wait to retrieve value from a function. Below code will run sequentially and once function is executed it will assign local storage value to variable 'mystoragevalue'.
var mystoragevalue = _ajustes.EsPrimeraVez();
console.log('TEST! Post');
and inside "ajustes":
public EsPrimeraVez() {
console.log('TEST! entrando en primeravez');
return this.storage.get('primeravez');
}
Hope this helps...Happy coding...!!!
Upvotes: 1