tabs 的html
<ion-tabs #myTabs>
<ion-tab [root]="tab1Root" (ionSelect)="select(0)" tabTitle="首页" tabIcon="home"></ion-tab>
<ion-tab [root]="tab2Root" (ionSelect)="select(1)" tabTitle="预测计划" tabIcon="disc"></ion-tab>
<ion-tab [root]="tab3Root" (ionSelect)="select(2)" tabTitle="开奖走势" tabIcon="pulse"></ion-tab>
<ion-tab [root]="tab4Root" (ionSelect)="select(3)" tabTitle="个人中心" tabIcon="contact"></ion-tab>
</ion-tabs>
tabs 的js
import { Component,ViewChild } from '@angular/core';
import { TrendPage } from '../trend/trend';
import { ForecastPage } from '../forecast/forecast';
import { MePage} from '../me/me';
import { HomePage } from '../home/home';
import {UserService} from "../../service/userService";
import {Tabs,Events} from "ionic-angular";//核心点
@Component({
templateUrl: 'tabs.html'
})
export class TabsPage {
tab1Root = HomePage;
tab2Root = ForecastPage;
tab3Root = TrendPage;
tab4Root = MePage;
private indexPage:number = 0;//核心点
@ViewChild('myTabs') tabs :Tabs;//核心点
constructor(public user:UserService,
public event:Events) {
}
select(index){
if (index == 1){
if(!this.user.login){
this.tabs.select(this.indexPage);//核心点
this.event.publish("loginAction",{});//核心点
}
}else {
this.indexPage = index;
}
}
}
子页面的js 订阅事件
event.subscribe("loginAction",(user,time)=>{
this.navCtrl.push(LoginPage);
});
在登陆页面登录后做返回!
self.navCtrl.pop();