hou*_*ous 2 typescript ionic-framework ionic3 angular
我正在使用Ionic 3,我有一些要求用户进行身份验证的功能,因此当用户点击按钮时,会显示警报.由于这些功能遍布整个项目,所以我创建了一个全局函数,显示了这个警告,但当我把它放入push()或setRoot()时,项目停止工作并出现一个空白页面.
import { Injectable, ViewChild } from '@angular/core';
//..............
@Injectable()
export class Alerts {
@ViewChild(Nav) nav: Nav;
constructor(private alertCtrl: AlertController) {
}
mustLogin() {
let alert = this.alertCtrl.create({
title: 'must login',
message: 'go to login ?',
buttons: [
{
text: 'Cancel',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
},
{
text: 'Login',
handler: () => {
this.nav.setRoot(LoginPage);
//this.nav.push(LoginPage); blank page also
}
}
]
});
alert.present();
}
Run Code Online (Sandbox Code Playgroud)
}
您需要遵循以下代码.
您可以在标题下阅读更多相关信息Navigating from an Overlay Component.
constructor(private appCtrl: App){}
Run Code Online (Sandbox Code Playgroud)
你需要使用 this.appCtrl.getRootNav().setRoot(LoginPage);
而不是这个this.nav.setRoot(LoginPage);
| 归档时间: |
|
| 查看次数: |
1783 次 |
| 最近记录: |