我正在尝试在离子应用程序中添加侧边菜单,但它不会出现,我正在附加所有文件,请帮助我!
app.html文件
<ion-menu [content]="mycontent">
<ion-header>
<ion-toolbar>
<ion-title>Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<button ion-item (click)=o nLoad(ServicesMessPage)>
<ion-icon name="quote" item-left></ion-icon>
Mess
</button>
<button ion-item (click)=o nLoad(ServicesLaundryPage)>
<ion-icon name="quote" item-left></ion-icon>
Laundry
</button>
</ion-list>
</ion-content>
</ion-menu>
<ion-nav [root]="rootPage" #mycontent></ion-nav>然后在app.component.ts中,我添加了所有必要的导入
app.component.ts文件
import { Component, ViewChild } from '@angular/core';
import { Platform, NavController, MenuController } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { LoginPage } from '../pages/login/login';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage: any = LoginPage;
@ViewChild('mycontent') nav: NavController
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, private menuCtrl: MenuController) {
platform.ready().then(() => {
statusBar.styleDefault();
splashScreen.hide();
});
}
onLoad(page: any) {
this.nav.setRoot(page);
this.menuCtrl.close();
}
}在ServicesPage html中,我包含了菜单
services.html
<ion-header>
<ion-navbar hideBackButton="true">
<ion-buttons start>
<button ion-button name="menu" menuToggle>
</button>
</ion-buttons>
<ion-title>Dashboard</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
</ion-content>发布于 2020-01-18 16:55:26
对于任何显示离子菜单的通用*.html文件,需要确保4件事:
中使用class="ion-page"
给定代码,stand通过单击菜单按钮显示sidemenu。
<ion-menu contentId="mainContent">
<ion-header>
<ion-toolbar>
<ion-title>Menu</ion-title>
</ion-toolbar>
</ion-header>
<!-- write your menu content here-->
</ion-menu>
<div class="ion-page" id = "mainContent" main>
<ion-buttons slot="start">
<ion-menu-button></ion-menu-button>
</ion-buttons>
<!-- write your app content here-->
</div>
注意:使用ion- menu -button的是切换菜单屏幕的方法之一。如Here所述,您还可以使用menuController更改菜单栏
发布于 2018-04-04 10:15:52
我在我的项目上测试了你的代码,它工作得很好,我唯一注意到的是你没有看到按钮中的图标菜单
更改此行
<button ion-button name="menu" menuToggle> </button>对于services.html中的这一个
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button> 使用此行,菜单的图标将会出现。
发布于 2018-04-04 11:45:03
首先,你在app.html,,,中的错误,可能是你的打字错误。现在我用以下代码重构你的代码:
<ion-menu [content]="mycontent">
<ion-header>
<ion-toolbar>
<ion-title>Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<button ion-item (click)=onLoad(ServicesMessPage)>
<ion-icon name="quote" item-left></ion-icon>
Mess
</button>
<button ion-item (click)=onLoad(ServicesLaundryPage)>
<ion-icon name="quote" item-left></ion-icon>
Laundry
</button>
</ion-list>
</ion-content>
</ion-menu>
<ion-nav [root]="rootPage" #mycontent></ion-nav>还需要在 services.html中进行更改
<ion-navbar hideBackButton="true">
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>Dashboard</ion-title>
</ion-navbar>https://stackoverflow.com/questions/49638764
复制相似问题