[英]How to redirect my ionic 2 app to a new page by using NavController from a provider
Current Scenario -- 当前方案-
I have a home page and I call a map service from this page to show a map in my app. 我有一个主页,并从该页面调用地图服务以在我的应用程序中显示地图。 This map service uses marker service to display different marker in the map.
该地图服务使用标记服务在地图中显示不同的标记。 Now I want to open a new page when user click on the info window of this marker.
现在,我想在用户单击该标记的信息窗口时打开一个新页面。 I have attached event listener for click on marker window as follows and is working fine
我已附加了事件侦听器,可单击标记窗口,如下所示,并且工作正常
marker.addEventListener(GoogleMapsEvent.INFO_CLICK).subscribe(
data => //Code to navigate to another page,
err => console.log("some error on marker listener ", err)
);
What I want -- 我想要的是 -
I want to redirect user to a new page from this click listener 我想将用户从此点击侦听器重定向到新页面
What I am doing now -- 我现在在做什么-
I have achieved this function by passing the public variable navCtrl from home page to marker service as arguments and calling push function as follow 我通过将公共变量navCtrl从首页传递到标记服务作为参数并按如下所示调用push函数来实现此功能
marker.addEventListener(GoogleMapsEvent.INFO_CLICK).subscribe(
data => navCtrl.push(OrderPickDetailsPage),
err => console.log("some error on marker listener ", err)
);
Question -- Is there any better way to do this? 问题-有更好的方法吗?
The one which you did is the correct and most simplest way of pushing a page when the listener method is triggered. 您执行的操作是触发侦听器方法时推入页面的正确且最简单的方法。
If the same page is pushed elsewhere in the code instead of rewriting the same push code you could just create a function and put that code inside it so you can reuse it in the class whenever you need it. 如果将同一页面推入代码中的其他位置,而不是重写相同的推入代码,则只需创建一个函数并将该代码放入其中,以便可以在需要时在类中重用它。
private pushOrderPickPage()
{
this.navCtrl.push(OrderPickDetailsPage);
}
Call this wherever you want in the class, 在课堂上任何地方都可以调用此名称,
this.pushOrderPickPage();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.