代码之家  ›  专栏  ›  技术社区  ›  johnny

如何导航到ionic 3中的侧菜单选项[关闭]

  •  -1
  • johnny  · 技术社区  · 8 年前

    我是爱奥尼亚的新手。我试图通过单击侧菜单选项来访问侧菜单选项。但我无法导航到该页面

    “无法读取未定义的属性‘component’”

    此错误。如何通过单击sode菜单选项访问这些页面。如果我使用push,那么所有选项都将是单个页面,而不是特定页面。

    import { Component, ViewChild } from '@angular/core';
    import { IonicPage, NavController, NavParams, Nav} from 'ionic-angular';
    import { DashboardPage } from '../dashboard/dashboard';
    import { ProfilePage } from '../profile/profile';
    import { sidemenuDeclaration } from '../../sideMenuDeclare';
    import { MenuController } from 'ionic-angular';
    import { FeaturesPage } from '../features/features';
    import { MediaPage } from '../media/media';
    import { BlogPage } from '../blog/blog';
    
    @IonicPage()
    @Component({
      selector: 'page-menu',
      templateUrl: 'menu.html',
    })
    export class MenuPage {
    @ViewChild(Nav) nav:Nav;
    
      rootPage:any = DashboardPage;
    
      constructor(public navCtrl: NavController, public navParams: NavParams, public menuCtrl: MenuController) {
      }
    
    options : sidemenuDeclaration[] = [
      {title : "Home" , icon : "home" ,component : DashboardPage},
      {title : "Features" ,icon : "settings" , component : FeaturesPage},
      {title : "Media" , icon : "images" , component : MediaPage},
      {title : "Blog" ,icon : "create" ,component : BlogPage},
      {title : "Contact" , icon : "contact" ,component : ProfilePage},
      {title : "Like Us" , icon : "logo-facebook" ,component : ProfilePage},
      {title : "Follow Us" , icon : "logo-twitter" ,component : ProfilePage}
    ]
    
      ionViewDidLoad() {
        console.log('ionViewDidLoad MenuPage');
      }
      goToProfile(){
        this.navCtrl.push(ProfilePage);
      }
    
      menuOptions(op){
        this.nav.setRoot(op.component);
      }
    
    }
    
    <ion-menu [content]='content'>
        <ion-header>
    
            <ion-toolbar color = "danger">
                <ion-title (click) = "goToProfile()">
                    <ion-icon name="contact"></ion-icon>Profile
                </ion-title>
            </ion-toolbar>
        </ion-header>
    
    
        <ion-content padding>
            <button ion-item *ngFor = "let op of options" (click) = "menuOptions()">
                <ion-icon name = {{op.icon}}></ion-icon>
                {{op.title}}
            </button>
        </ion-content>
    
    </ion-menu>
    
    <ion-nav #content [root]="rootPage"></ion-nav>
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   DivineCoder    8 年前

    功能 menuOptions 需要一个未在(html)模板中传递的参数。 使用以下代码段。

       <ion-content padding>
            <button ion-item *ngFor = "let op of options" (click) = "menuOptions(op)">
                <ion-icon name = {{op.icon}}></ion-icon>
                {{op.title}}
            </button>
        </ion-content>
    
    推荐文章