Ionic 4 : ngOnInit vs ionViewWillEnter

Varun Sukheja picture Varun Sukheja · Jan 21, 2019 · Viewed 17.1k times · Source

Which is better to use Angular Lifecycle Hook or Ionic Lifecycle hooks specially for initialization when creating a hybrid app using Ionic 4?

Angular lifecycle hook - ngOnInit

ngOnInit() {
    this.getData();
}

Ionic lifecycle hook - ionViewWillEnter

ionViewWillEnter() {
    this.getData();
}

Answer

siva kumar picture siva kumar · Mar 1, 2019

ionViewWillEnter — Fired when entering a page (also if it’s come back from stack)

ngOnInit will not be triggered, if you come back to a page after putting it into a stack

i think better once ionviewwillenter