I intend to disable the swipe gesture for the side menu in the log in page. The only change I made is importing the MenuController and set swipeEnable to false in the constructor.
However, after running it, I keep getting a syntax error: Unexpected token (18:47) while parsing file.
import {App, Page, NavController, Nav,NavParams, IonicApp, Storage, LocalStorage, MenuController } from 'ionic-angular';
import {httpService} from '../../services/httpService';
import {HelloIonicPage} from '../hello-ionic/hello-ionic';
import {GettingStartedPage} from '../getting-started/getting-started';
import {SettingsPage} from '../settings/settings';
@Page({
templateUrl: 'build/pages/log-in/log-in.html',
providers: [httpService]
})
export class LoginPage {
static get parameters(){
return [[NavController],[httpService],[MenuController]];
}
constructor(navController, httpService, menu: MenuController) {
this.menu = menu;
this.navController = navController;
this.httpService = httpService;
this.local = new Storage(LocalStorage);
this.menu.swipeEnable(false);
}
}
Thanks in advance.
The ion-side-menu-content element can use its own attribute. When the drag-content attribute is set to false, it will disable the ability to open the side menu by swiping the content screen.
Menu Button | ion-menu-button to Open an App Menu on A Page.
The following worked for me on Ionic2 v.2.2.0
src/app/app.html
and add an ID to your <ion-menu>
elementSo that this,
<ion-menu [content]="content">
Becomes this.
<ion-menu id="myMenu" [content]="content">
Open login.html
and remove the <ion-navbar>
code from <ion-header>
so that the menu will not display on the page.
Open login.ts
and import the MenuController
from ionic/angular
.
In the constructor set enable()
on MenuCtrl
to false
and add the menu ID as the second parameter. Even though the menu isn't showing, doing this will prevent the user from swiping to open the menu.
import { Component } from '@angular/core';
import { NavController, MenuController } from 'ionic-angular';
@Component({
selector: 'page-login',
templateUrl: 'login.html'
})
export class LoginPage {
constructor(
public navCtrl: NavController,
public menuCtrl: MenuController
) {
this.menuCtrl.enable(false, 'myMenu');
}
}
import { MenuController } from 'ionic-angular';
constructor(....... ........ .......... .......,private menu : MenuController)
ionViewDidEnter() {
// the root left menu should be disabled on this page
this.menu.enable(false);
}
ionViewWillLeave() {
// enable the root left menu when leaving this page
this.menu.enable(true);
}
this will hide the menu
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With