[英]Ionic Data Storage
I have local storage session_storage
, how can I give to variable ttt
value dogovor
from session_storage
?我有本地存储
session_storage
,如何从session_storage
给变量ttt
值dogovor
?
ttt: any = this.storage.get('session_storage', 'dogovor');
Sample above is not working.上面的示例不起作用。
Thanks!谢谢!
To set an item设置项目
this.storage.set('YOUR_KEY', 'YOUR_VALUE');
for eg:例如:
this.storage.set('session_storage', 'dogovor');
To get the item获取物品
this.storage.get('YOUR_KEY').then((value) => {
console.log(value);
});
for eg:例如:
// declare
private ttt = '';
// get data from storage
this.storage.get('session_storage').then((value) => {
console.log(value);
this.ttt = value;
});
There are basically two functions to store and retrieve data,基本上有两个函数来存储和检索数据,
Ionic 3: @ionic/storage functions get
y set
离子3:@离子/存储功能
get
ÿ set
Ionic 4: @ionic-native/native-storage/ngx functions getItem
y setItem
离子 4: @ionic-native/native-storage/ngx函数
getItem
y setItem
1) to store a value
related to a key
use, 1) 存储与
key
使用相关的value
,
Ionic 3 this.storage.set('key', 'value')
离子 3
this.storage.set('key', 'value')
Ionic 4 returns a Promise
Ionic 4 返回一个
Promise
let value = null;
this.storage.set('key', 'value').then(
() => console.log('Value stored!'),
error => console.log(error)
);
2) to retrieve from store a value
using the related key
use get
, this function returns a Promise
, an example 2) 使用相关
key
从 store 中检索value
使用get
,此函数返回一个Promise
,一个例子
Ionic 3离子 3
let value = null;
this.storage.get('key').then(
data => value = data,
error => console.log(error)
);
Ionic 4, similar to Ionic 3 just change function name set
to setItem
Ionic 4,类似于 Ionic 3 只是将函数名称
set
为setItem
loadCustomer(){
return new Promise(resolve => {
this.storage.get('session_storage').then((res)=>{
this.anggotae = res;
this.dogovor = this.anggotae.dogovor;
digi: this.dogovor;
console.log(this.dogovor);
});
let body = {
aksi : 'getdata',
limit : this.limit,
start : this.start,
dogovor: this.digi,
};
this.postPvdr.postData(body, 'proses-api.php').subscribe(data => {
for(let customer of data.result){
this.customers.push(customer);
}
resolve(true);
});
});
}
There is an error.有错误。 This is not working
这不起作用
let body = {
aksi : 'getdata',
limit : this.limit,
start : this.start,
dogovor: this.digi,
};
Variable 'dogovor' is not active.变量 'dogovor' 不活跃。 Where is my mistake?
我的错误在哪里?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.