如何从离子2中的导航获取当前页面
问题描述:
我是Ionic2的新手,我正在尝试根据当前菜单选择构建动态标签。我只是想知道如何使用导航控制器获取当前页面。
I am new to Ionic2, and I am trying to build dynamic tabs based on current menu selection. I am just wondering how can I get current page using navigation controller.
...
export class TabsPage {
constructor(navParams: NavParams,navCtrl:NavController) {
//here I want to get current page
}
}
...
从api文档我觉得 getActiveChildNav()
或 getActive()
会给我当前页面,但我不知道 ViewController
/ Nav
。
From api documentation I feel getActiveChildNav()
or getActive()
will give me the current page, but I have no knowledge on ViewController
/Nav
.
任何帮助将不胜感激。提前致谢。
Any help will be appreciated. Thanks in advance.
答
完整示例:
import { NavController } from 'ionic-angular';
export class Page {
constructor(public navCtrl:NavController) {
}
(...)
getActivePage(): string {
return this.navCtrl.getActive().name;
}
}
获取当前页面名称的方法:
Method to get current page name:
this.navCtrl.getActive().name
更多细节此处