在我们实际使用中往往有这么一种需求:当你进入子页面操作之后,返回要刷新父页面的内容。比如,我做了一个笔记功能,在笔记父页面里(A),内容是我保存的笔记,这个时候我点击添加笔记,跳转到添加笔记页面(B),我写好我的笔记之后点击保存,这个时候跳转回我的笔记父页面,我要父页面的内容显示了我刚刚添加的那一则笔记。
(1)在A页面和B页面中也别引入Eventsimport { Events } from 'ionic-angular';
并在构造函数中声明
public events: Events
(2)B(子)页面中要跳转的地方添加如下代码
this.navCtrl.pop().then(()=>{
this.events.publish('reloadNotePage');
});
(3)A(父)页面中ionViewDidLoad()添加如下代码
this.events.subscribe('reloadNotePage',() => {
this.items = new Array();
let that = this;
var localpoi:any[]=new Array();
this.storage.get('note').then((data)=>{
if(data==null){
alert("没有数据");
}
else{
localpoi = data;
console.log(localpoi);
for(var i = 0;i<localpoi.length;i++){
var poi = localpoi[i];
that.items.push(poi);
}
}
});