Tôi mới đến Ionic 2 & Angular2 và tôi đã tải về một mẫu Ionic mới với lệnh sauDisable swipe bên menu để mở cử chỉ cho trang đăng nhập (hoặc bất kỳ trang nào) trong Ionic 2
Ionic start appname sidemenu --v2 --ts
Đối với giải pháp cụ thể này, tôi đã thêm một trang đăng nhập để xác thực người dùng. Sau khi xác thực thành công, người dùng sẽ được điều hướng đến trang menu sử dụng menu bên.
Khi giải pháp dựa trên mẫu sidemenu
, menu bên đang hiển thị trên trang đăng nhập bất cứ khi nào người dùng vuốt sang trái.
Vì vậy, ai đó có thể vui lòng hướng dẫn tôi sửa lỗi này và ngăn menu bên hiển thị khi chế độ xem được vuốt.
Mã của tôi
App.ts nộp
import {App, IonicApp, Platform,MenuController} from 'ionic-angular';
import {StatusBar} from 'ionic-native';
import {HelloIonicPage} from './pages/hello-ionic/hello-ionic';
import {ListPage} from './pages/list/list';
import {HomePage} from './pages/home/home';
@App({
templateUrl: 'build/app.html',
config: {} // http://ionicframework.com/docs/v2/api/config/Config/
})
class MyApp {
// make HelloIonicPage the root (or first) page
rootPage: any = HomePage;
pages: Array<{title: string, component: any}>;
constructor(
private app: IonicApp,
private platform: Platform,
private menu: MenuController
) {
this.initializeApp();
// set our app's pages
this.pages = [
{ title: 'Hello Ionic', component: HelloIonicPage },
{ title: 'My First List', component: ListPage }
];
}
initializeApp() {
this.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();
});
}
openPage(page) {
// close the menu when clicking a link from the menu
this.menu.close();
// navigate to the new page if it is not the current page
let nav = this.app.getComponent('nav');
nav.setRoot(page.component);
}
}
tập tin app.html
<ion-menu side-menu-content drag-content="false" [content]="content">
<ion-toolbar>
<ion-title>Pages</ion-title>
</ion-toolbar>
<ion-content>
<ion-list>
<button ion-item *ngFor="#p of pages" (click)="openPage(p)">
{{p.title}}
</button>
</ion-list>
</ion-content>
</ion-menu>
<ion-nav id="nav" [root]="rootPage" #content swipe-back-enabled="false"></ion-nav>
Homepage.ts nộp (trang đăng nhập trong trường hợp này).
import {Page, Events,Alert,NavController,Loading,Toast,Storage,LocalStorage,SqlStorage} from 'ionic-angular';
import { FORM_DIRECTIVES, FormBuilder, ControlGroup, Validators, AbstractControl } from 'angular2/common';
import {HelloIonicPage} from '../hello-ionic/hello-ionic';
import {NgZone} from 'angular2/core';
@Page({
templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
public Uname :string;
public usrvalid:boolean;
public usrpwd :boolean;
public usrpwdlength:boolean;
public usrvalidlength:boolean;
public isUnchanged:boolean;
public usrpwdzero:boolean;
public usrvaliddigits:boolean;
rootpage:any;
public Upwd:string;
constructor(public nav:NavController) {
this.nav=nav;
this.isUnchanged=true;
var mediumRegex = new RegExp("^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})");
// rootPage: any = HomePage;
}
}
Đối với bất kỳ ai gặp khó khăn khi vuốt swipeEnable (sai) để hoạt động, có thể do menu của bạn chưa được khởi tạo. Nếu bạn cố gắng làm điều này trên mẫu Hello Ionic, nó sẽ không hoạt động trong hàm dựng nhưng sẽ ở bên trong 'platform.ready(). Then' block – Todd
Tôi có cùng một tình huống như người hỏi, tôi đã làm mã của tôi giống như câu trả lời của bạn . Nhưng, sau khi đăng nhập, tôi điều hướng đến Trang A, nhưng nó không có biểu tượng trên thanh menu trong đó. Sau đó, tôi trượt để mở danh sách menu, tôi nhấp lại trang đó, sau đó đột nhiên nó có biểu tượng thanh trình đơn. Tôi đặt điều này 'this.menu.swipeEnable (false);' trong bộ điều khiển trang A. Cảm ơn trước. –
ionViewDidLoad() { this.menu.swipeEnable (sai, 'trái'); } – Christer