【发布时间】:2019-08-15 11:55:33
【问题描述】:
我对 Angular/TypeSript/Ionic 4 相当陌生,所以这可能有点傻,但我使用的是 Ionic Storage 插件,你可以在此页面“https://ionicframework.com/docs/building/storage”中找到它。我遇到了 我的公平份额的麻烦。文档很清楚但是太简单了。
我需要检查我的存储空间是否为空,并查看存储空间的内容。
首先,我尝试通过长度来处理它,期望它返回一个数字,但在服务上使用此代码:
getLenght(){
return this.storage.length().then((res) => {
return res;
});
}
我页面上的这段代码我得到了一个对象结果:
storageLength : any; // it would give me error as a Number
clearStorage() {
this.dataStorageService.clear();
this.storageLength = this.dataStorageService.getLenght(); // returns object promise
alert(JSON.stringify(this.storageLength));
//{"__zone_symbol__state":null,"__zone_symbol__value":[]}
然后我尝试了这个,但由于错误,我什至无法运行它:
this.storage.get("qrCodeData").then( this.storage.get("qrCodeData") =>{}).catch(err=>{
console.log("Your data don't exist and returns error in catch: " + JSON.stringify(err);
});
错误是“'Promise' 类型的参数不可分配给 '(value: any) => any' 类型的参数。 类型 'Promise' 不匹配签名 '(value: any): any'"
所以不确定如何验证存储是否为空,因为我遇到了各种各样的问题,我在这里错过了什么?
【问题讨论】:
标签: angular typescript ionic-framework