Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload the ion-page after pop() in ionic2

I have 2 pages Page1 and Page2. I have used this.nav.pop() in Page2 and it will pop the Page2 and Page1 will enable but i want to refresh the Page1. Thank you in advance.

like image 867
Akash Rao Avatar asked Mar 31 '16 06:03

Akash Rao


3 Answers

you could pass the parent page along with the nav push. that way you could accces the parent page as a navParamter.
in parent page:

 goToChildPage() {     this.navCtrl.push(ChildPage, { "parentPage": this });  } 

and in the child page before pop you could call functions on parent page

this.navParams.get("parentPage").someFnToUpdateParent();   //or this.navParams.get("parentPage").someFnToRefreshParent(); 
like image 67
noel zubin Avatar answered Sep 23 '22 03:09

noel zubin


Ignore the direct angular implementations suggested here, especially since you are using Ionic 2 and the suggestions are assuming Ionic 1. Don't start mixing too much of direct angular in your ionic app unless there is no ionic implementation for what you need. Import "Events" from ionic/angular2 in both Page1 and Page2, then in Page2 do something like

this.events.publish('reloadPage1');
this.nav.pop();

And in Page1 put

this.events.subscribe('reloadPage1',() => {
 this.nav.pop();
 this.nav.push(Page1);
});
like image 32
Jonathan Bardi Avatar answered Sep 20 '22 03:09

Jonathan Bardi


You may want to implement one of these in your page:

ionViewWillEnter ionViewDidEnter

Please review the navController and page lifecycle documentation: http://ionicframework.com/docs/v2/api/components/nav/NavController/

like image 41
user2674268 Avatar answered Sep 21 '22 03:09

user2674268