disable menu on login page ionic 4

后端 未结 7 1513
北荒
北荒 2021-01-11 13:33

I use the beta of ionic 4 for the first time. I try to disable the menu on a login page, but i have some trouble.

I\'ve created the app with ionic-cli and the sideme

7条回答
  •  攒了一身酷
    2021-01-11 14:25

    none of the above answers worked for me.

    I did a test to check the order in which the methods were executed and this is what I got:

    1.initializeApp

    2.ngOnInit

    2.1 platform ready

    image app.component.ts

    example, console output, from platfor ready within initializeApp image output initializeApp

    the console.log ('ionViewDidEnter') inside the ionViewDidEnter was never displayed by console

    try the following scenario for yourself where the above described is evident

    sorry for my English

    app.component.ts

    import { Component, OnInit } from '@angular/core';
    import { Platform, MenuController } from '@ionic/angular';
    import { SplashScreen } from '@ionic-native/splash-screen/ngx';
    import { StatusBar } from '@ionic-native/status-bar/ngx';
    
    @Component({
      selector: 'app-root',
      templateUrl: 'app.component.html',
      styleUrls: ['app.component.scss']
    })
    export class AppComponent implements OnInit {
      public selectedIndex = 0;
      public appPages = [
        {
          title: 'Inbox',
          url: '/folder/Inbox',
          icon: 'mail'
        },
        {
          title: 'Outbox',
          url: '/folder/Outbox',
          icon: 'paper-plane'
        },
        {
          title: 'Favorites',
          url: '/folder/Favorites',
          icon: 'heart'
        },
        {
          title: 'Archived',
          url: '/folder/Archived',
          icon: 'archive'
        },
        {
          title: 'Trash',
          url: '/folder/Trash',
          icon: 'trash'
        },
        {
          title: 'Spam',
          url: '/folder/Spam',
          icon: 'warning'
        }
      ];
      public labels = ['Family', 'Friends', 'Notes', 'Work', 'Travel', 'Reminders'];
    
      constructor(
        private platform: Platform,
        private splashScreen: SplashScreen,
        private statusBar: StatusBar,
        private menu: MenuController
      ) {
        this.initializeApp();
      }
    
      initializeApp() {
        console.log('initializeApp');
        
        return this.platform.ready().then(() => {
          console.log('platform ready')
          this.statusBar.styleDefault()
          this.splashScreen.hide()
          // // -------------------------------------------------// 
          // this.menu.enable(false, "custom")                   //
          // this.menu.isEnabled('custom').then((enable)=>{      // => yes working
          //   console.log('enable from platform ready', enable);//
          // });                                                 //
          // //--------------------------------------------------//
        });
      }
    
      ngOnInit() {
        console.log('ngOnInit');
        //  // ---------------------------------------------// 
        //  this.menu.enable(false, "custom")               //
        //  this.menu.isEnabled('custom').then((enable)=>{  // => yes working
        //    console.log('enable from ngOnInit', enable);  //
        //  });                                             //
        //  //----------------------------------------------//
        const path = window.location.pathname.split('folder/')[1];
        if (path !== undefined) {
          this.selectedIndex = this.appPages.findIndex(page => page.title.toLowerCase() === path.toLowerCase());
        }
      }
      ionViewDidEnter(){
        console.log('ionViewDidEnter')
        //  // ---------------------------------------------// 
        //  this.menu.enable(false, "custom")               //
        //  this.menu.isEnabled('custom').then((enable)=>{  // => not working
        //    console.log('enable ionViewDidEnter', enable);//
        //  });                                             //
        //  //----------------------------------------------//
      }
    
    }
    

    app.component.html

    
      
        
          
            
              Inbox
              hi@ionicframework.com
    
              
                
                  
                  {{ p.title }}
                
              
            
    
            
              Labels
    
              
                
                {{ label }}
              
            
          
        
        
      
    
    

提交回复
热议问题