javascript - Ionic 2 菜单转换

标签 javascript node.js typescript menu ionic2

我遵循了 ionic 2 的菜单文档,我想这样显示菜单: enter image description here

所以菜单显示在内容页面下方,菜单按钮仍然显示。

但是当我运行我的应用程序时,我得到了这个:

enter image description here

菜单显示在内容页面上方,按钮消失了! 这是 app.html 代码:

<ion-split-pane>
    <ion-menu side="left" id="loggedInMenu" [content]="content">
        <ion-header>
            <ion-toolbar>
                <ion-title>Menu</ion-title>
            </ion-toolbar>
        </ion-header>

        <ion-content>
            <ion-list>
                <button ion-item menuClose="loggedInMenu" *ngFor="let p of appPages" (click)="openPage(p)">
                    <ion-icon item-start [name]="p.icon" [color]="isActive(p)" ></ion-icon>
                    {{p.title}}
                </button>
            </ion-list>
        </ion-content>
    </ion-menu>
    <!-- main navigation -->
    <ion-nav [root]="rootPage" #content swipeBackEnabled="false" main name="app"></ion-nav>

</ion-split-pane>

app.componenent.ts :

import { Component, ViewChild } from '@angular/core';
import { Platform,MenuController, Nav, } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { HomePage } from '../pages/home/home';
import { LoginPage } from '../pages/login/login';
import { MainPage } from '../pages/main/main';
import { MyDogsPage } from '../pages/my-dogs/my-dogs';
import { MyCoursesPage } from '../pages/my-courses/my-courses';
import { FriendsPage } from '../pages/friends/friends';
import { TrainersPage } from '../pages/trainers/trainers';
import { AuthenticationProvider } from '../providers/authentication/authentication'



export interface PageInterface {
  title: string;
  component: any;
  icon: string;
  index?: number;

}


@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  @ViewChild(Nav) nav: Nav;
  appPages: PageInterface[] = [
    { title: 'Account', component: MainPage, index: 0, icon: 'finger-print' },
    { title: 'My Dogs',  component: MyDogsPage,index: 1, icon: 'paw' },
    { title: 'My Course', component: MyCoursesPage, index: 2, icon: 'book' },
    { title: 'Friends', component: FriendsPage, index: 3, icon: 'people' },
    { title: 'My Trainers', component: TrainersPage, index: 4, icon: 'man' },

  ];
  rootPage:any;
  currentTitle ='';
  activePage:any;
  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, public userData: AuthenticationProvider, public menuctrl: MenuController) {
    this.rootPage=(localStorage.disableintro? LoginPage:HomePage)
    this.userData.hasLoggedIn().then((hasLoggedIn) => {
      this.enableMenu(hasLoggedIn === true);
    });
    this.enableMenu(false);

    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();
      splashScreen.hide();
    });
  }

  enableMenu(loggedIn: boolean) {
    this.menuctrl.enable(loggedIn, 'loggedInMenu');
  }


  openPage(page) {
    let params = {};
    console.log('dd');

    this.nav.setRoot(page.component, params).catch((err: any) => {
      console.log('rr');

        console.log(`Didn't set nav root: ${err}`);
    });

    this.activePage=page;
  }

  isActive(page: PageInterface) {
    let childNav = this.nav.getActiveChildNavs()[0];

    // Tabs are a special case because they have their own navigation
    if (childNav) {
      if (childNav.getSelected() ) {
        return 'primary';
      }
      return;
    }

    if (this.nav.getActive() && this.nav.getActive().name === page.title) {
      return 'primary';
    }
    return;
  }
}

请帮忙。

最佳答案

尝试添加 type='reveal给你的<ion-menu> -元素:

<ion-menu type='reveal' side="left" id="loggedInMenu" [content]="content">

docs说:
'Material Design 和 Windows 模式的默认类型都是 overlay , 和 reveal是 iOS 模式的默认类型。'

您要显示的结果以 iOS 模式显示。您得到的结果是在 Material Design 模式下。

关于javascript - Ionic 2 菜单转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45334445/

相关文章:

visual-studio - 如何在构建后事件中启动 Typescript 编译

node.js - Node Express从404文件请求中区分404页面请求

javascript - react 组件DidMount "Parsing error: Missing semicolon"

javascript - 如何防止应用程序继续,直到 Javascript 中的值或条件准备就绪

javascript - 我对 .splice() 做错了什么

javascript - Express js 路由器不工作

node.js - 如何使用 nodejs 在 Redis 缓存中创建 LIKE 运算符搜索?

javascript - 使用 'document.querySelector' 查找元素后,“单击”功能在 typescript/angular 中不起作用

html - 为什么单击的项目没有在下拉列表中被选中,而是始终显示标题文本

javascript - emberjs 一次获取所有表单字段/值