我有一个页面 Page2
,有时需要使用 modal()
打开,有时需要使用 push()
打开。
在正常情况下,如果使用推送方法打开 Controller ,它将显示一个“后退”按钮。但是,在使用 modal()
方法打开页面的另一种情况下,我需要向 Page2
添加一个关闭按钮,以便用户可以随时关闭该 Controller 时间。
问题
如果我向 Page2
添加一个关闭按钮,那么即使 Controller 是使用 push()
方法打开的,该按钮也会显示,在这种情况下,它会显示一个后退按钮和一个关闭按钮。
我想要什么
我想添加一个条件,如果 Controller 是使用 push()
打开的,那么它应该隐藏那个关闭按钮
流程:
Page 1 > (Push to) > Page 2 (Hide the close button)
Page 3 > (Modal to) > Page 2 (Show the close button)
关于如何实现这一点有什么想法吗?
最佳答案
您可以向 Page2
构造函数发送一个参数,如下所示:
presentPage2AsModal() {
let page2Modal = this.modalCtrl.create(Page2, { showCloseBtn: true });
page2Modal.present();
}
如果你用push
方法打开它:
openPage2AsPage() {
this.nav.push(Page2, { showCloseBtn: false });
}
然后在 Page2
构造函数中:
constructor(..., private navParams: NavParams) {
// Get the param
this.showCloseBtn = navParams.get('showCloseBtn');
}
在 View 中:
<button *ngIf="showCloseBtn" (click)="yourMethod">Close</button>
关于javascript - Ionic2 - 根据 Controller 的显示方式显示/隐藏按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38425384/