使用Onsen UI返回参数的PopPage [英] PopPage with returning parameters with Onsen UI

查看:201
本文介绍了使用Onsen UI返回参数的PopPage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个页面: page1.html 有一个按钮,可使用pushPage('page2.html')打开 page2.html .然后,我想有一个可选参数(我正在使用单选按钮)返回给 page1.html ,所以我使用$scope.appNavigator.popPage({myParam: myValue}),但在 page1.html的控制器上没有参数. 我希望找到具有以下内容的myParam

I have two pages: page1.html has a button that opens page2.html with pushPage('page2.html'). Then I would like to have a selectable parameter (I'm using radio buttons) to be returned to page1.html, so I use $scope.appNavigator.popPage({myParam: myValue}), but at the controller of page1.html there're no params. I expected to find myParam with:

var page = $scope.accidentInvestigationNavigator.getCurrentPage();
$scope.myParam = page.options.myParam;

是否可以使用popPage()将参数发送到上一页?...如果没有,如何返回参数?

Is it possible to send parameters to the previous page with popPage()?... if not, how could I return with a parameter?

推荐答案

pushPage使用自定义options创建新的页面对象,但是popPage不会创建或覆盖任何内容,因此您无法传递自定义向后.这不是一个错误,它现在只是像这样设计.

pushPage creates a new page object with the custom options but popPage doesn't create nor overwrite anything, so you cannot pass custom options backwards. This is not a bug, it is just designed like that right now.

在AngularJS中的控制器之间共享信息的方式有很多:服务,父控制器,事件广播...

There are many ways to share information between controllers in AngularJS: services, parent controllers, event broadcast...

我在这里用3种不同的方法作了一个例子: http://codepen.io/frankdiox/pen /XbvzKJ

I have made an example with 3 different approaches here: http://codepen.io/frankdiox/pen/XbvzKJ

我认为最有趣的方法是在执行popPage时使用Onsen的prepop事件共享信息.

I think the most interesting way is to use Onsen's prepop event to share information when you do a popPage.

希望有帮助!

这篇关于使用Onsen UI返回参数的PopPage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆