Angular 如何设置storageservice值';门店标识';在Ionic4中,角度为6的变量中
我正在尝试从Ionic4(6)中的storageservice获取store_id。我是通过这样做才得到商店的Angular 如何设置storageservice值';门店标识';在Ionic4中,角度为6的变量中,angular,ionic4,Angular,Ionic4,我正在尝试从Ionic4(6)中的storageservice获取store_id。我是通过这样做才得到商店的 let id=this.storageService.get('store_id'); id.then(数据=>{ this.store.push(数据) }); 我把它推入阵列。现在我无法检索该存储id。我正在执行var store\u id=this.store[0]但它显示未定义 我的StorageService代码如下 异步集(键:字符串,值:任意):承诺{ 试一试{ con
let id=this.storageService.get('store_id');
id.then(数据=>{
this.store.push(数据)
});
我把它推入阵列。现在我无法检索该存储id。我正在执行var store\u id=this.store[0]
但它显示未定义
我的StorageService代码如下
异步集(键:字符串,值:任意):承诺{
试一试{
const result=wait this.storage.set(键,值);
log('在存储器中设置字符串:'+结果);
返回true;
}捕获(原因){
控制台日志(原因);
返回false;
}
}
获取键/值对的步骤
异步获取(键:字符串):承诺{
试一试{
const result=wait this.storage.get(key);
log('storageGET:'+key+':'+result);
如果(结果!=null){
返回结果;
}
返回null;
}捕获(原因){
控制台日志(原因);
返回null;
}
}
设置键/值对象
异步setObject(键:字符串,对象:对象){
试一试{
const result=wait this.storage.set(key,JSON.stringify(object));
log('set Object in storage:'+result);
返回true;
}捕获(原因){
控制台日志(原因);
返回false;
}
}
获取键/值对象
异步getObject(键:字符串):Promise{
试一试{
const result=wait this.storage.get(key);
如果(结果!=null){
返回JSON.parse(result);
}
返回null;
}捕获(原因){
控制台日志(原因);
返回null;
}
}
删除单个键值:
删除(键:字符串){
此。存储。删除(键);
}
从应用程序中删除所有数据:
clear(){
这个.storage.clear();
}
在安装了ionic storage和cordova storage之后,我通过ionic create service StorageService创建了此服务
请帮忙。。提前感谢您可以通过以下代码解决:
异步yourMethodName(){
让data=wait this.storageService.get('store_id');
这个.store.push(数据);
}
你能添加你的storageService
code吗?@KishanBharda正在编辑问题,请等待,同样的未定义。。请等待向您发送屏幕快照。在调用this.storageService.get('store\u id')
之前,您是否正在访问var store\u id=this.store[0]
。。我在从StorageService获取店铺id后调用它