2

I need an event of page which is backed. IonWillEnter or ionViewDiEnter events aren't fired when page is backed. Ionic framework seems to show page simply when a back button is clicked. Would you like to teach me? Sorry for my poor English.

Thanks

ahadortiz
  • 916
  • 1
  • 9
  • 20

2 Answers2

1

For your info.. Ionic 2 lifecycle method

ionViewDidLoad - works the same way as ngOnInit, fires once when the view is initially loaded into the DOM

ionViewWillEnter and ionViewDidEnter - hooks that are available before and after the page becomes active

ionViewWillLeave and ionViewDidLeave - hooks that are available before and after the page leaves the viewport

ionViewWillUnload - is available before the page is removed from the DOM

You should use ionViewWillLeave / ioniViewDidLeave to track the page back/close event

digit
  • 4,479
  • 3
  • 24
  • 43
  • 2
    let me explain in detail. I'm on Page1. And then I go to Page 2. And then I go back to Page 1 by clicking on 'back' button. On page1, how can I know that page is backed? – ahadortiz Jun 17 '17 at 19:54
  • 1
    Then, you can use ionViewWillEnter (page1 will enter) or ionViewDidEnter(after page1 fully loaded). – digit Jun 17 '17 at 20:04
  • Put ionViewDidEnter method in page1. You can try console.log in the ionViewDidEnter method after hitting back button in page2. If you think this is helped, please upvote. Tq anyway. – digit Jun 17 '17 at 20:06
0

According to https://ionicframework.com/blog/navigating-lifecycle-events/

ionViewWillEnter: It’s fired when entering a page, before it becomes the active one. Use it for tasks you want to do every time you enter in the view (setting event listeners, updating a table, etc.).

ionViewDidEnter: Fired when entering a page, after it becomes the active page. Quite similar to the previous one.

So you can use any of above. I prefer ionViewDidEnter more in this scenario so screen render faster if you call any API.

Vivek Chaturvedi
  • 530
  • 5
  • 16