【发布时间】: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