Ionic get Active Page

ぃ、小莉子 提交于 2019-12-22 14:59:08

问题


I am using Ionic 3 and want to get the name of the active page in order to identify which page I am on in an event subscription.

When I am on a page, the following works:

this.nav.getActive().name

However, if my root is tabs and I want to identify the page loaded in a tab, the above code just returns the tab page name and not the active page.

Question

How do I get the active page name or identifier if it is loaded in a tab?


回答1:


You can get the component of the page.

Like this this.nav.getActive().component

In the tabs page get your tabs element in ViewChild like this:

@ViewChild('myTabs') tabRef: Tabs;

After that attempt to get selected tab:

this.nav.getActive().component.tabRef.getSelected().root

This will give you the page




回答2:


In Ionic 3.9.2 you can get even the instance of the current Page with

this.viewController.instance

This lets you access to all the Page class/member methods with a simple cast.

<YuorPageClass>this.viewController.instance.yourMethod()

The official documentation is incomplete, or outdated at the moment.



来源:https://stackoverflow.com/questions/43809063/ionic-get-active-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!