您好我正在研究Ionic 2 beta 11.但似乎有很多错误..
我有Ionic 2标签的问题。 问题是标签没有设置为root .. 手段当应用程序打开时,我按下任何选项卡,再次按下其他一些选项卡.. 然后按下按钮它没有关闭应用程序,但导航到上一个标签/页面。
我的代码:
app.ts
import {Component,Inject, ViewChild,enableProdMode} from "@angular/core";
import {Platform, ionicBootstrap,MenuController, NavController,Keyboard}from 'ionic-angular';`
import {StatusBar, Splashscreen} from 'ionic-native';
import {TabsPage} from './pages/tabs/tabs';
import {SigninPage} from './pages/signin/signin';
import {disableDeprecatedForms, provideForms} from '@angular/forms';
import {EventDetailsPage} from './pages/event-details/event-details';
import {AuthService} from "./pages/signin/authservice";
import {myEvents} from "./pages/myEvents/myEvents";
import {Page1} from './pages/page1/page1';
// import {enableProdMode} from 'angular2/core';
import {Geolocation} from 'ionic-native';`
declare var navigator:any;
declare var cordova:any;
enableProdMode();`
@Component({
templateUrl: 'build/app.html',
providers: [AuthService]
})
export class MyApp {
rootPage: any;
userEvents: any = myEvents;
// static companyLogin:boolean;
@ViewChild('content') nav: NavController;
public local = null;
constructor(platform: Platform, public menu: MenuController, keyboard: Keyboard) {
platform.ready().then(() => {
console.log('platform works..');
Splashscreen.hide();
StatusBar.styleDefault();
// cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// cordova.plugins.Keyboard.disableScroll(false);
// cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// keyboard.disableScroll(true)
let local = window.localStorage.getItem('ecnob.token');
let getType = window.localStorage.getItem('type');
if(local == null){
this.rootPage = SigninPage;
// console.log("app ts root Nav");
this.menu.enable(false);
}
else{
// if(getType == 1){
// console.log('type value',getType);
// MyApp.companyLogin = true;
// }
// else{
// MyApp.companyLogin = false;
// console.log('type value',getType);
// }
this.menu.enable(true);
this.rootPage = TabsPage;
// console.log('company login',MyApp.companyLogin);
}
}
)}
//================ MY Events Screen =============//`
goEvents(){
this.nav.push(myEvents);
}
//================ MY Events Screen END =============//
//======================== LOG OUT FUNCTION ===================///
logout(){
AuthService.logout().then((succ)=>{
console.log('loogin out');
this.menu.enable(false);
this.nav.setRoot(SigninPage);
},(err)=>{
console.log('getting error',err);
// window.alert('Something went wrong.. Please try again');
})
}
}
//============================== END ===============================//
ionicBootstrap(MyApp, [
disableDeprecatedForms(),
provideForms()
],{tabsPlacement: "bottom",tabsHideOnSubPages: true,
tabsHighlight: true})
app.html:
<ion-menu [content]="content">
<ion-content>
<!-- Some side menu contents -->
</ion-content>
<ion-nav id="nav" #content [root]="rootPage" swipeBackEnabled="false"> </ion-nav>`
标签HTML:
<ion-tabs class="foo-tabs" #myTabs primary>
<ion-tab [root]="tab1Root" tabTitle="Home" (ionSelect)="select(0)" tabIcon="home"></ion-tab>
<ion-tab [root]="tab2Root" tabTitle="Deals" (ionSelect)="select(1)" tabIcon="pricetags" ></ion-tab>
<ion-tab [root]="tab3Allevent" tabTitle="Events" (ionSelect)="select(2)" tabIcon="calendar"></ion-tab>
<ion-tab [root]="tab4Root" tabTitle="Companies" (ionSelect)="select(3)" tabIcon="grid"></ion-tab>
</ion-tabs>`
标签ts:
import {Component,ViewChild} from "@angular/core";
import {Page1} from '../page1/page1';
import {CreateDealPage} from '../create-deal/create-deal';
import {Page3} from '../page3/page3';
import {AllCompaniesPage} from '../all-companies/all-companies';
import {AllEventsPage} from '../all-events/all-events';
import {DealsPage} from '../deals/deals';
import {EventDetailsPage} from '../event-details/event-details';
import {NavController,NavParams,MenuController,Tabs} from 'ionic-angular';
import {DataService} from '../../service/dataService/dataService';
// import {SigninPage} from '../signin/signin';
@Component({
templateUrl: 'build/pages/tabs/tabs.html'
})
export class TabsPage {
private param;
// this tells the tabs component which Pages
// should be each tab's root Page
@ViewChild('myTabs') myTabs: Tabs;
ionViewDidEnter() {
// window.alert('view enter');
var t: Tabs = this.nav.parent;
t.select(this.param);
// this.nav.getActive();
// console.log('privous tab',this.myTabs);
// this.nav.parent.select(tabIndex);
}
select(param){
console.log('param select',param);
this.param = param;
// var t: Tabs = this.nav.parent;
// t.select(0);
}
private tab1Root: any;
private tab2Root: any; //deals Page
private tab3Allevent: any;
private tab4Root: any ;
constructor(public nav:NavController){
this.tab1Root = Page1;
this.tab2Root = DealsPage;
this.tab3Allevent = AllEventsPage;
this.tab4Root = AllCompaniesPage
}
}
不知道......下一步是什么