简体   繁体   English

如何通过提供商使用NavController将Ionic 2应用程序重定向到新页面

[英]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.

相关问题 在Ionic 2应用程序中导航NavController已解决! 但在Ionic 3中却没有 - Navigation NavController in Ionic 2 app SOLVED! but not in Ionic 3 在一个应用程序中使用 NavController 和 BottomNavigation - Using NavController and BottomNavigation in one app 如何在不丢失我的ID和密码的情况下将我的应用程序从一页重定向到另一页 - how to redirect my app to from one page to another page without loosing my id and password in android 如何使用 navController 在 Jetpack Compose 中从一个屏幕导航到另一个屏幕? - How to navigate from a screen to another in Jetpack Compose using navController? 登录后如何将android应用重定向到新页面 - How to redirect android app to new page after login 如何使用 flutter 从二维码重定向到我的应用程序中的页面? - How can I do a redirect from a qr code to a page within my app with flutter? 如何从我的设备中查看离子应用程序中的错误 - How to see errors from an ionic app from my device 如何重定向到Ionic应用程序的基本URL? - How to redirect to an Ionic app's base URL? 使用 NavController 从片段导航到另一个片段 - Navigate from fragment to another using NavController 我如何从另一个应用程序重定向到我的应用程序 - How can i redirect from another app to my app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM