Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ionic framework 等待本地存储_Ionic Framework_Async Await_Local Storage - Fatal编程技术网

Ionic framework 等待本地存储

Ionic framework 等待本地存储,ionic-framework,async-await,local-storage,Ionic Framework,Async Await,Local Storage,我需要等待localStorage检索一个值,然后才能继续我的函数。。。我读到我必须使用“async/await”指令,但我发现没有一个示例真正有效 我的代码是 _ajustes.EsPrimeraVez().then (async (promAjuste)=> { await console.log('TEST! en el then'); }); console.log('TEST! Post'); 在“ajustes”中: 但它并不等待结果继续。。。这可能吗?

我需要等待localStorage检索一个值,然后才能继续我的函数。。。我读到我必须使用“async/await”指令,但我发现没有一个示例真正有效

我的代码是

  _ajustes.EsPrimeraVez().then (async (promAjuste)=> {
    await console.log('TEST! en el then');
  });
  console.log('TEST! Post');
在“ajustes”中:

但它并不等待结果继续。。。这可能吗?
谢谢大家,新年快乐

如果要等待从函数中检索值,为什么要使用prmoise/then syntac。下面的代码将按顺序运行,一旦函数执行,它将为变量“mystoragevalue”分配本地存储值

var mystoragevalue = _ajustes.EsPrimeraVez();
console.log('TEST! Post');
在“ajustes”中:


希望这有帮助…快乐编码

我被教导要永远回报承诺。。。我不知道你可以依次做。。。你救了我!谢谢问题是mystoragevalue没有实际价值,只有承诺。。。我如何读取值?我已经计算出。。。在那个物体上做一个“.then”。。。就像它是异步的。。。
var mystoragevalue = _ajustes.EsPrimeraVez();
console.log('TEST! Post');
public EsPrimeraVez() {
   console.log('TEST! entrando en primeravez');
   return this.storage.get('primeravez');
}