[英]ionic3- How to save data in localstorage and retrieve data in next page
How to save data in localstorage and retrieve data in next page.I don't know How to do This?When I Tried The following code I get the data(voter_id)in console successfully but data is not displayed on home.html
page 如何将数据保存在本地存储中以及如何在下一页中检索数据?我不知道该怎么办?尝试以下代码时,我成功在控制台中获取了数据(voter_id),但数据未显示在
home.html
页面上
Here is my code
这是我的代码
check.html
check.html
<ion-header>
<ion-navbar>
<ion-title>check</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-list>
<ion-item>
<ion-label floating>voter_id</ion-label>
<ion-input type="text" value="" [(ngModel)]="userData.voter_id"></ion-input>
</ion-item>
</ion-list>
<button ion-button full color="lightText" (click)="check()">submit</button>
</ion-content>
Check.ts
Check.ts
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import { HomePage } from '../home/home';
@IonicPage()
@Component({
selector: 'page-check',
templateUrl: 'check.html',
})
export class CheckPage {
userData:any={
'voter_id':''
};
constructor(public navCtrl: NavController, public navParams: NavParams,
private storage: Storage) {
}
ionViewDidLoad() {
console.log('ionViewDidLoad CheckPage');
}
check()
{
window.localStorage.setItem('voter_id', this.userData.voter_id);
let voterId= window.localStorage.getItem('voter_id');
console.log(window.localStorage.getItem('voter_id'));
this.navCtrl.push(HomePage);
}
}
From check page I need to save data(voter_id) into localStorage and retrieve that data(voter_id) in next page home.html
.Here I need to display the data in homepage(near voter_id in home.html
page) not in console. 从检查页面中,我需要将数据(voter_id)保存到localStorage并在下一页
home.html
检索该数据(voter_id)。在这里,我需要在主页中( home.html
页面中的表决者ID附近)显示数据,而不是在控制台中显示数据。 How to do this? 这个怎么做? I don't whether I need to add anything in
home.html
and home.ts
to retrieve data 我是否不需要在
home.html
和home.ts
添加任何内容来检索数据
home.html
home.html
<ion-item>
voter_id :
</ion-item>
Need to change in home.ts
file like: 需要更改
home.ts
文件,例如:
pubilc voter_id:any;
constructor() {
this.voter_id = window.localStorage.getItem('voter_id');
}
And also need change in home.html 并且还需要更改home.html
<ion-item>
voter_id : {{voter_id }}
</ion-item>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.