Ionic life cycle ionViewdidEnter not working

大城市里の小女人 提交于 2019-12-23 15:24:10

问题


I have an ionic 2 app. It has a tab inside tab view. There are two tabs. Home and Feed. The Feed page has two new tabs , Users and Freinds. The root of Feed is Users page and Users page has an ionViewDidEnter method.

The problem I am facing is with this method not firing when I toggle between the parent tabs Home and Feed. If I toggle between Users and Friends it works. Otherwise only the life cycles in parent components work.

How can I solve this issue? Is there any work around to quickly fix this?

export class TabsPage {
  tab1Root: any = FeedPage;
  tab2Root: any = HomePage;
  constructor(public navCtrl: NavController , public auth: Authentication , public book: Bookemon) {}
}

tabs.html

<ion-tabs selectedIndex="0" tabsPlacement="top">
  <ion-tab [root]="tab2Root" tabTitle="home" tabIcon="book"></ion-tab>
  <ion-tab [root]="tab3Root" tabTitle="feed" tabIcon="compass"></ion-tab>
</ion-tabs>

The seconds tabs are in FeedPage

export class FeedPage {
  tab1root = UsersPage;
  tab2root = FriendsPage;
  constructor( public navCtrl: NavController ) {}
  ionViewDidEnter () {
    // console.log('ran');
  }
}

feed.html

<ion-tabs selectedIndex="0" >
  <ion-tab [root]="tab1Root" tabTitle="users" tabIcon="bonfire"  ></ion-tab>
  <ion-tab [root]="tab2Root" tabTitle="freinds" tabIcon="book"></ion-tab>
</ion-tabs>

users.ts

export class UsersPage {
  constructor( public navCtrl: NavController ) {}
  ionViewDidEnter () {
    console.log('ran');
    // not running when toggling between ``feed`` and ``home``
  }
}

来源:https://stackoverflow.com/questions/41091621/ionic-life-cycle-ionviewdidenter-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!