2
我是ionic2和TypeScript的新手。無法在ionic2中打開菜單
我的問題是如何打開ionic2菜單?
當我按下page1中的菜單圖標時,以下代碼不起作用。 而我在page1.ts中嘗試app.getComponent('leftMenu').enable(true);
,但是當我運行該應用程序時,頁面變爲空白屏幕。
有沒有人給我任何建議或提示?
page1.html
<ion-navbar *navbar>
<button menuToggle="leftMenu">
<ion-icon name='menu'></ion-icon>
</button>
<ion-title>Page 1</ion-title>
</ion-navbar>
<ion-content padding class="page1">
<h2>Welcome to Ionic!</h2>
</ion-content>
page1.ts
import {IonicApp, Page} from 'ionic-angular';
@Page({
templateUrl: 'build/pages/page1/page1.html',
})
export class Page1 {
constructor(app: IonicApp) {
//app.getComponent('leftMenu').enable(true); <- screen becomes blank.
}
}
app.ts
import {App, IonicApp, Platform, MenuController} from 'ionic-angular';
import {StatusBar} from 'ionic-native';
import {Page1} from './pages/page1/page1';
import {Page2} from './pages/page2/page2';
@App({
template: `
<ion-menu [content]="content" id="leftMenu" side="left">
<ion-toolbar>
<ion-title>Pages</ion-title>
</ion-toolbar>
<ion-content>
<ion-list>
<button ion-item (click)="openPage(page1)">
Page1
</button>
<button ion-item (click)="openPage(page2)">
Page2
</button>
</ion-list>
</ion-content>
</ion-menu>
<ion-nav [root]="rootPage"></ion-nav>`,
config: {} // http://ionicframework.com/docs/v2/api/config/Config/
})
export class MyApp {
rootPage: any = Page1;
page1: any = Page1;
page2: any = Page2;
constructor(
platform: Platform,
private menu: MenuController,
private app: IonicApp
) {
this.menu = menu;
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
StatusBar.styleDefault();
});
}
openPage(page) {
// Reset the nav controller to have just this page
// we wouldn't want the back button to show in this scenario
this.rootPage = page;
// close the menu when clicking a link from the menu
this.menu.close();
}
}
感謝您的一種解釋和有用的信息進行編輯。 – tomo