我正在尝试检索localStorage值;但是,我无法获得任何值,我的日志如下所示:
日志是:{}
到目前为止,这是我的代码:
import {Storage, LocalStorage} from 'ionic-angular';
//I am storing here
this.local = new Storage(LocalStorage);
this.local.set('options', 'op2');
//In the chrome developer tools, I can see that the value was stored successfully in localStorage
//I can't see anything, when trying to retrieve the stored value
console.log('log is : '+ JSON.stringify(this.local.get('options')));
答案 0 :(得分:1)
如果您阅读了我在其他问题here中提供的文档,您会发现set
没有立即解决,而是返回一个承诺。如果您立即尝试get
而不是等待Promise
解决方案,则最有可能的结果是存储仍为空。
答案 1 :(得分:1)
您可以通过以下方式从localStorage读取值:
this.local.get('options').then(value => console.log(value))