Ionic得到活跃的页面 [英] Ionic get Active Page
问题描述
我正在使用Ionic 3并希望获取活动页面的名称,以便确定我在活动订阅中所在的页面。
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
但是,如果我的root是标签,并且我想识别标签中加载的页面,则上面的代码只返回标签页名称而不是活动页面。
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.
问题
如何获取活动页面名称或标识符(如果它被加载到选项卡中?)
How do I get the active page name or identifier if it is loaded in a tab?
推荐答案
您可以获取页面的组件。
You can get the component of the page.
喜欢这个 this.nav.getActive()。component
在标签页在ViewChild中获取您的标签元素,如下所示:
In the tabs page get your tabs element in ViewChild like this:
@ViewChild('myTabs') tabRef: Tabs;
尝试获取选定标签后:
this.nav.getActive().component.tabRef.getSelected().root
这将为您提供页面
这篇关于Ionic得到活跃的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!