(1)如1.3 所寫,測滑菜單寫在app.html,因此測滑菜單中的各個按鈕的實現就在app.component.ts中寫了,若是像其餘普通界面同樣在app.component.ts中引入NavController並在構造函數constructor中聲明public navCtrl:NavController就會報錯,那麼,在app.html中正確進行界面跳轉的方法爲
(2)引入ViewChild和Navjavascript
import { Component,ViewChild } from '@angular/core'; import { Platform,Nav} from 'ionic-angular';
(3)聲明css
@ViewChild(Nav) nav: Nav;
(4)跳轉html
this.nav.push(SettingsPage);
(5)所有代碼java
import { Component,ViewChild } from '@angular/core'; import { Platform,Nav} from 'ionic-angular'; import { StatusBar } from '@ionic-native/status-bar'; import { SplashScreen } from '@ionic-native/splash-screen'; import { TabsPage } from '../pages/tabs/tabs'; import { LoginPage } from '../pages/login/login'; import { SettingsPage } from '../pages/settings/settings'; @Component({ templateUrl: 'app.html' }) export class MyApp { // 父組件中使用@ViewChild拿到子組件的變量和方法(父組件可調用子組件的方法和變量) // 這裏引入的是app.html <ion-nav> @ViewChild(Nav) nav: Nav; rootPage:any = TabsPage; constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) { platform.ready().then(() => { statusBar.styleDefault(); splashScreen.hide(); }); } push_mysettings(){ this.nav.push(SettingsPage); } }