I have two page with two components:

*PAGES:*
HOME & ABOUT 

with two components

*COMPONENTS:*
Home.component & About.component

When I redirect from Home to About page and vice versa, I want to call a 
Webapi before it routes to another page

I have tried 2 things:

1. ngOnDestroy
2. Subscribe Router Events


Example: Let's say I am navigating from *Home => About* page, so inside the 
home component method, Below are the two cases 


Home.component.ts :::: Calling Webapi method inside *ngOnDestroy* method.

*------------------------------------------ ngOnDestroy 
---------------------------------------------------------*

*public ngOnDestroy(): void {*
        
        this.updateChanges(); *// Indside this method http call is there*
        
        // Unsubscribe from all subscriptions
        this._unsubscribeAll.next();
        this._unsubscribeAll.complete();
*}*

*----------------------------------------------- Router 
------------------------------------------------------------*

Home.component.ts :::: Calling Webapi by Subscribing *Router* change events

*public ngOnDestroy(): void {*

this._router.events.subscribe((ev: Event) => {
           if (ev instanceof NavigationStart) {
                this.updateChanges(); *// Indside this method http call is 
there*
           }
        }
);

*}*

*---------------------------------------------------------------------------------------------------------------------*

*PROBLEM is: Inside network tab in browser I can see that Webapi is getting 
called but status is showing Cancelled. Any idea why?*


-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/angular/0ac3b5a2-e0c9-4dad-a58a-bd5ea268d2e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to