我发现this question的已接受答案确实有用,但发现它也会禁用滑动以关闭手势。
有没有办法只让它打开菜单而不关闭它?当我试图关闭它并认为滑动手势会修复它时,我发现它有点反应迟钝。我无法在Ionic docs中找到任何相关内容。
['style-loader', 'css-loader', 'sass-loader']
答案 0 :(得分:2)
在Ionic中没有默认方法,但您可以使用ionOpen
和ionClose
回调来处理何时应启用滑动功能或者禁用:
<ion-menu persistent="true" [content]="content"
(ionOpen)="enableSwipe()" <!-- Enable it when opening -->
(ionClose)="disableSwipe()"> <!-- Disable it when closing -->
<ion-header>
<ion-toolbar color="primary">
<ion-title>Side menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
</ion-content>
</ion-menu>
<!-- Disable swipe-to-go-back because it's poor UX to combine STGB with side menus -->
<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>
import { Component, ViewEncapsulation } from '@angular/core';
import { MenuController } from 'ionic-angular';
import { HomePage } from '../pages/home/home';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
public rootPage: any = HomePage;
constructor(private menuCtrl: MenuController) {}
ngAfterViewInit() {
this.disableSwipe();
}
public enableSwipe(): void {
this.menuCtrl.swipeEnable(true);
}
public disableSwipe(): void {
this.menuCtrl.swipeEnable(false);
}
}