ionic 3 在底部导航tabs中做登陆!!

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();

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值