[英]Is there a way to manually delete a page and then navigate to it and reinitialize it again using ionic2
For example i am displaying a home page after login.
In the Home screen i have a menu in that menu i have options as New Flight,Home.
When i click on the home button i will load Home Screen only.
For that i am using navctrl.push(HomePage). Every time user clicks that button
it is adding the same page multiple time into the navigation stack.
can you please tell me how to solve this problem.whenever user clicks the Home Button it want to remove the previous home page and newly it want to add the Home page.how can i achieve this?
下面是我的component.ts文件代碼
項目清單
import { Component } from '@angular/core'; import { IonicPage, Nav, NavParams, App, ViewController } from 'ionic-angular'; import { NewflightPage } from '../newflight/newflight'; import { RolesactionPage } from '../rolesaction/rolesaction'; import { EditProfilePage } from '../edit-profile/edit-profile'; import { ManagePeoplePage } from '../manage-people/manage-people'; import { HomePage } from '../home/home'; @IonicPage() @Component({ selector: 'page-main', templateUrl: 'main.html', }) export class MainPage { constructor(public navCtrl: Nav, public navParams: NavParams, public viewCtrl: ViewController,public appCtrl: App) { } ionViewWillEnter() { var lc = document.createElement('script'); lc.type = 'text/javascript'; lc.src = 'assets/js/dialog.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(lc, s); } rolesAction() { this.navCtrl.push(RolesactionPage); } myFlightAction() { this.navCtrl.push(MainPage); } } Above is the my component code. I am calling myFlightAction() from main.html like below <a (click)="myFlightAction()"><img src="assets/imgs/flight-depart.png" alt="My Flights"> My Flights</a>
請告訴我我錯了。當我通過檢查瀏覽器來檢查瀏覽器時,是否每次都將其作為z-index 101重新添加……每次。當我單擊“我的航班”按鈕時。 您還能告訴我每次加載每個離子頁面所需的Java腳本文件的方法嗎?
出問題的是,您要推送一個新頁面,這樣它將始終有一個新頁面,而不會關閉最后一頁。 在這種情況下,您需要使用setRoot
方法。
myFlightAction() {
this.navCtrl.setRoot(MainPage);
}
請注意,這將清除導航堆棧並將MainPage
設置為您的第一頁。
推入頁面只是將另一個頁面放入導航堆棧中,這就是為什么它為您推入的每個頁面提供較高值的z-index
。 顧名思義, setRoot
導航堆棧的根組件設置為所需的組件。
您需要知道所在頁面的索引是什么,以便可以將其從堆棧中刪除。 由於我不知道頁面的順序,也不知道如何相互訪問,或者即使順序是動態的,我們也將首先獲取頁面控制器,以便e可以獲取其索引,然后再推入另一頁面,然后您將刪除上一個。
myFlightAction() {
// Get the controller of the active page
const myActualController = this.navCtrl.getActive();
// Get the index of the active page
const pageIndex: number = this.navCtrl.indexOf(myActualController);
// Push your new page
this.navCtrl.push(MainPage).then(() => {
// In the callback of your push method, after successfully pushing your the page, you'll remove this page based on his index.
this.navCtrl.remove(pageIndex);
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.