Call child Page method from TabsPage

I have 3 Tabs. I have TabsPage and I want to call method of FavoritesPage.methodToCall() from TabsPage. I saw this: Call a Page method within a Component But ngAfterViewInit for TabsPage is never called. I have used ngAfterViewInit in other Pages and it works fine.

export class TabsPage {

   tab1Root: any = HomePage;
   tab2Root: any = XXXPage;
   tab3Root: any = FavoritesPage;
   
   @ViewChild('myTabs') tabRef: Tabs;

   @ViewChild(FavoritesPage) favoritesPage: FavoritesPage;

   constructor() {}

   ngAfterViewInit() {
     if (this.favoritesPage != null)
        this.favoritesPage.test();  // doesnt work
   } 

   // called on tab changed
   onIonChange() {
     // I want to call method of FavoritesPage
    
    // doesnt work 
    this.tabRef.getSelected().root  <- this return Page
    this.tabRef.getSelected().root.methodToCall();

    // also doesnt work
    if (this.favoritesPage != null)
            this.favoritesPage.methodToCall();
    
    // TODO: How to do it?  
   }
1 Like