How to call page unloaded event in nativescript angular


I can’t seem to get the unloaded event to fire using my angular app.

<Page xmlns="" (unloaded)="onUnloaded">

Is what i have. in my component:

        console.log('Navigated to detail');

It’s not getting called.
I do have Page injected into my component if that matters. Anyone know what I need to do? I want to set visibility off an Activity spinner on unload so when navigating back it isn’t spinning.


You would not declare your Page in HTML when using Angular, it’s created and handled internally by page router outlet. The page instance can be injected in your constructor.

Besides, may I know why you may need unloaded event when you have ngDestroy from Angular Component Life Cycle.


Probably because I’m a newbie. I’ve changed it to ngDestroy() but that doesn’t seem to get called when I navigate away. If it is a life cycle event, wouldn’t it get called when navigating away from a page?


OK, I figured it out. ngOnDestroy doesn’t seem to get called, but I can initialize the page on events in the ngOnInit(). So I did this:

ngOnInit() {'navigatingTo', (data) => {
        // run init code
        // (note: this will run when you either move forward or back to this page)