Angular 离子3本机存储器读取存储的值
你好, 在我的代码中,我尝试了本机存储插件页面上编写的代码,如下所示: 当我启动android模拟器设备时,控制台会向我发回以下信息:Angular 离子3本机存储器读取存储的值,angular,typescript,cordova-plugins,ionic3,cordova-nativestorage,Angular,Typescript,Cordova Plugins,Ionic3,Cordova Nativestorage,你好, 在我的代码中,我尝试了本机存储插件页面上编写的代码,如下所示: 当我启动android模拟器设备时,控制台会向我发回以下信息: [00:02:01] console.log: Stored item! [00:02:01] console.log: [object Object] 我想找到一个读取存储信息的解决方案。因为我想使用存储在本机存储中的值在外部页面上设置条件,而我不能。示例“如果存储在名称可控震源的本机存储上的值==为true,则启动此函数”。我正在寻找读取值的方法
[00:02:01] console.log: Stored item!
[00:02:01] console.log: [object Object]
我想找到一个读取存储信息的解决方案。因为我想使用存储在本机存储中的值在外部页面上设置条件,而我不能。示例“如果存储在名称可控震源的本机存储上的值==为true,则启动此函数”。我正在寻找读取值的方法。你能帮我吗
谢谢要读取该值,请这样称呼它:
console.log(data.property);
console.log(data.anotherProperty);
请参阅插件github以获得更清晰的理解:您无法获得这样的值,因为它是一个
异步
操作。您只是尝试复制/粘贴文档的代码。这不是真正的用法用例。这只是一个例子
这是真实的用例模拟。您存储的值如下所示
my-first-page.ts
在第2页上,您可以检索如下值
my-second-page.ts
注意:如果您需要进一步的帮助,请告诉我。我完全按照您的解释做了,我添加了我想要的“财产”的财产价值。我把它放在家里
在参数中,我将
this.nativeStorage.getItem('myitem')
.then(
data => console.log(data.property),
error => console.error(error)
);
当我运行模拟器时,我的控制台会告诉我何时在回家的速度上跌倒
[10:30:06] console.log: Stored item!
[10:30:06] console.log: deviceready has not fired after 5 seconds.
[10:30:06] console.log: Ionic Native: deviceready event fired after 4017 m
s
当我点击页面parameter.ts时,这里是我得到的结果
[10:56:17] console.log: value
[10:56:17] console.error: [object Object]
我知道“财产”的价值等于“价值”
谢谢大家我完全按照你们说的做了,但运气不好。请帮忙
this.nativeStorage.setItem('myitem', {property: 'value', anotherProperty: 'anotherValue'})
.then(
() => console.log('Stored item!'),
error => console.error('Error storing item', error)
);
this.nativeStorage.getItem('myitem')
.then(
data => console.log(data.property),
error => console.error(error)
);
[10:30:06] console.log: Stored item!
[10:30:06] console.log: deviceready has not fired after 5 seconds.
[10:30:06] console.log: Ionic Native: deviceready event fired after 4017 m
s
[10:56:17] console.log: value
[10:56:17] console.error: [object Object]