gpt4 book ai didi

angular - ionic2:无法从弹出窗口导航到另一个页面

转载 作者:搜寻专家 更新时间:2023-10-30 22:05:19 24 4
gpt4 key购买 nike

我正在使用 Ionic2,我想在用户从弹出窗口中选择要打开的页面时打开另一个页面,这是第一页中的代码:

popvarSpecialsArr = ['Home','My Account','Cart','Wishlist','My Orders'];
presentPopoverSpecial(myEvent) {
let popover = this.popoverCtrl.create(MorePopverPage, {popvarArr: this.popvarSpecialsArr});
console.log('my event', myEvent);
popover.present({
ev: myEvent
});

}

这是来自弹出页面的代码:

popvarArr;

constructor(public navCtrl: NavController, public navParams:
NavParams,public viewCtrl: ViewController) {
this.popvarArr = this.navParams.get('popvarArr');
console.log(this.navParams.get('popvarArr'));
}

openPage(page) {
console.log(page);
if(page == 'Home') {
console.log('inside home');
this.navCtrl.setRoot(HomePage);
} else if(page == 'My Account') {
this.navCtrl.setRoot(MyAccountPage);
} else if(page == 'Cart') {
this.navCtrl.setRoot(CartPage);
} else if(page == 'Wishlist') {
this.navCtrl.setRoot(WishlistPage);
} else if(page == 'My Orders') {
this.navCtrl.setRoot(MyOrdersPage);
} else if(page == 'Specials') {
this.navCtrl.setRoot(SpecialsPage);
}
}

这是弹出窗口的 Html 代码

<ion-content no-padding no-margin>
<ion-list no-lines no-padding no-margin>
<button ion-item *ngFor="let popvar of popvarArr" (click)="openPage(popvar)">{{popvar}}</button>
<!-- <button ion-item (click)="close()">Home</button>
<button ion-item (click)="close()">My Account</button>
<button ion-item (click)="close()">Cart</button>
<button ion-item (click)="close()">Wishlist</button>
<button ion-item (click)="close()">My Orders</button> -->
</ion-list>

但是当我从弹出窗口中选择一个页面时,它没有显示我想要的页面并且仍然在同一页面中,我应该怎么做才能显示弹出窗口中的其他页面

最佳答案

就像您在 the docs 中看到的那样:

What if you wanted to navigate from an overlay component (popover, modal, alert, etc)? In this example, we've displayed a popover in our app. From the popover, we'll get a reference of the root NavController in our app, using the getRootNav() method.

import { Component } from '@angular/core';
import { App, ViewController } from 'ionic-angular';

@Component({
template: `
<ion-content>
<h1>My PopoverPage</h1>
<button ion-button (click)="pushPage()">Call pushPage</button>
</ion-content>
`
})
class PopoverPage {
constructor(
public viewCtrl: ViewController
public appCtrl: App
) {}

pushPage() {
this.viewCtrl.dismiss();
this.appCtrl.getRootNav().push(SecondPage);
}
}

所以在你的情况下,它看起来像这样:

import { App, ViewController } from 'ionic-angular';

// ...

constructor(public viewCtrl: ViewController, public appCtrl: App) {}

// ...

openPage(page) {
console.log(page);

// Close the popover
this.viewCtrl.dismiss();

if(page == 'Home') {
console.log('inside home');
this.appCtrl.getRootNav().setRoot(HomePage);
} else if(page == 'My Account') {
this.appCtrl.getRootNav().setRoot(MyAccountPage);
} else if(page == 'Cart') {
this.appCtrl.getRootNav().setRoot(CartPage);
} else if(page == 'Wishlist') {
this.appCtrl.getRootNav().setRoot(WishlistPage);
} else if(page == 'My Orders') {
this.appCtrl.getRootNav().setRoot(MyOrdersPage);
} else if(page == 'Specials') {
this.appCtrl.getRootNav().setRoot(SpecialsPage);
}
}

关于angular - ionic2:无法从弹出窗口导航到另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45811876/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com