PopPage with returning parameters with Onsen UI

2019-07-07 20:43发布

问题:

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;

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

回答1:

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.

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

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

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

Hope it helps!



标签: onsen-ui