【问题标题】:Ionic 2: LocalStorage between pagesIonic 2:页面之间的LocalStorage
【发布时间】:2016-07-08 00:39:28
【问题描述】:

我的应用有两个页面,我想使用 localstorage 保存应用的数据。

这是我的第一页:

constructor(public nav : NavController){

    this.local = new Storage(LocalStorage);
    this.array = [];
    this.nav = nav;
    this.information= this.local.get('obj'); 
    this.array.push(this.information);  //storing data in array from locals
    console.log(this.array);
}

gotopage(){
    this.nav.push(SecPage);   //going to second page where input fields are
} 

这就是我使用 localstorage 在第二页中设置数据的方式,其中输入字段如下。

构造函数:

this.local = new Storage(LocalStorage);

onSubmit 方法

this.local.set('obj', value);
this.navigation.pop(); 

现在我想显示第一页数组中的数据,但什么都没有显示。

<ion-card *ngFor= "#arr of array">
<img src=""/>
<ion-card-content>
<ion-card-title>
{{arr.name}}
</ion-card-title>
</ion-card-content>
</ion-card>

我想当我从第二页到第一页时存在持久性问题。你能确定为什么数组中的数据没有显示吗?

【问题讨论】:

  • 我认为你正在做相反的事情。 localStorage 是全局的,而不是 array

标签: ionic-framework angular local-storage ionic2 angular-local-storage


【解决方案1】:
this.local.getItem('obj')
  .then(
     this.information=data;
  );

检查您是否以正确的方式从存储中获取数据。

console.log(this.information)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-19
    • 1970-01-01
    • 1970-01-01
    • 2017-06-29
    • 2016-08-21
    • 2017-10-21
    • 1970-01-01
    • 2021-04-12
    相关资源
    最近更新 更多