I noticed that the ngOnInit()
method gets not called when I come back to the page which is already instanced. I have to use any other method for this? I need a method which is called everytime when he is visiting the specific page.
EDIT
Tested already onPageWillEnter()
but it gets not fired in Ionic 2
Check Lifecycle Events section in the link.
You can use ionic 2 lifecycle hook
ionViewWillEnter(){
//your methods
}
If you change a route so that only a parameter value changed, then the component is reused.
You can use
constructor(router:Router) {
router.params.subscribe(val => myInit());
}
to call your initialization code instead of using ngOnInit()
in such cases.
To recall ngOnInit everytime when page is visiting, you should use ngOnDestroy. For example, if your component content depends on code in url, you should use OnDestroy, in this way:
export class GRMTasksComponent implements OnInit, OnDestroy {
subParams: Subscription;
ngOnInit() {
this.subParams = this._route.params.subscribe(params => {
//some code...
});
}
ngOnDestroy() {
this.subParams.unsubscribe();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With