2

我的应用程序有两个页面,我想使用本地存储保存应用程序的数据。

这是我的第一页:

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>

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

4

1 回答 1

0
this.local.getItem('obj')
  .then(
     this.information=data;
  );

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

console.log(this.information)
于 2018-07-13T08:54:29.633 回答