问题
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