ionic3实现侧菜单与ionic1不同。用的是menuToggle控件。
官方参考文档实例:https://github.com/ionic-team/ionic-preview-app/blob/master/src/pages/menus/basic/pages.ts
可以使用命令:ionic start test sidemenu
来建一个带侧菜单的demo。
文件结构
实例
home.html
<ion-header>
<ion-navbar>
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<h3>Ionic Menu Starter</h3>
<p>
If you get lost, the <a href="http://ionicframework.com/docs/v2">docs</a> will show you the way.
</p>
<button ion-button secondary menuToggle>Toggle Menu</button>
</ion-content>
app.html
<ion-menu [content]="content" side="right">
<ion-header>
<ion-toolbar>
<ion-title>MenuList</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<button menuClose ion-item *ngFor="let p of pages" (click)="openPage(p)">
{{p.title}}
</button>
</ion-list>
</ion-content>
</ion-menu>
<!-- Disable swipe-to-go-back because it's poor UX to combine STGB with side menus -->
<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>
side=”right”:可以控制菜单栏出来的方向是左侧还是右侧。