mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-21 21:15:24 +08:00

Menu has been improved to make it easier to open, close, toggle and enable menus. Instead of injecting `IonicApp` to find the menu component, you now inject `MenuController`. Was: ``` constructor(app: IonicApp) { this.app = app; } openMenu() { this.app.getComponent('leftMenu').close(); } ``` Now: To programmatically interact with any menu, you can inject the `MenuController` provider into any component or directive. This makes it easy get ahold of and control the correct menu instance. By default Ionic will find the app's menu without requiring a menu ID. An id attribute on an `<ion-menu>` is only required if there are multiple menus on the same side. If there are multiple menus, but on different sides, you can use the name of the side to get the correct menu If there's only one menu: ``` constructor(menu: MenuController) { this.menu = menu; } openMenu() { this.menu.close(); } ``` If there is a menu on the left and right side: ``` toggleMenu() { this.menu.toggle('left'); } ``` If there are multiple menus on the same side: ``` <ion-menu id="myMenuId" side="left">...</ion-menu> <ion-menu id="otherMenuId" side="left">...</ion-menu> closeMenu() { this.menu.close('myMenuId'); } ```
57 lines
1.0 KiB
HTML
57 lines
1.0 KiB
HTML
|
|
<ion-navbar *navbar>
|
|
|
|
<button menuToggle="left">
|
|
<ion-icon name="menu"></ion-icon>
|
|
</button>
|
|
|
|
<ion-title>
|
|
Menu
|
|
</ion-title>
|
|
|
|
<ion-buttons end>
|
|
<button>
|
|
<ion-icon name="football"></ion-icon>
|
|
</button>
|
|
</ion-buttons>
|
|
|
|
<ion-buttons start>
|
|
<button>
|
|
<ion-icon name="baseball"></ion-icon>
|
|
</button>
|
|
</ion-buttons>
|
|
|
|
<button menuToggle="right" right secondary>
|
|
<ion-icon name="menu"></ion-icon>
|
|
</button>
|
|
|
|
</ion-navbar>
|
|
|
|
|
|
<ion-content padding>
|
|
|
|
<h3>Page 1</h3>
|
|
|
|
<p>
|
|
<button class="e2eContentToggleMenu" menuToggle="left">Toggle Left Menu</button>
|
|
</p>
|
|
|
|
<p>
|
|
<button menuToggle="right">Toggle Right Menu</button>
|
|
</p>
|
|
|
|
<ion-card>
|
|
<ion-item>
|
|
<ion-label>Username:</ion-label>
|
|
<ion-input></ion-input>
|
|
</ion-item>
|
|
</ion-card>
|
|
|
|
<p>
|
|
<button (click)="presentAlert()">Open alert</button>
|
|
</p>
|
|
|
|
<f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f>
|
|
|
|
</ion-content>
|