4

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?

itwasntme
  • 1,442
  • 4
  • 21
  • 28
  • Hello, thanks for your response. Tag is "onsen-ui", as per I'm using Onsen UI. In its guide, at onsen.io/reference/ons-navigator.html#method-popPage, it says that Options can be sent as parameters (like pushPage). The code is already described above. – Pablo Aguirre Aug 24 '15 at 17:56

1 Answers1

4

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!

Fran Dios
  • 3,482
  • 2
  • 15
  • 26
  • Thanks a lot Fran!... I've used a service as you recommended, with `ons-prepop` at navigator to fire a `$scope.$broadcast('update')` to refresh the value at `page1.html`. – Pablo Aguirre Aug 25 '15 at 12:27
  • With 2.0 is there anyway to pass information using straight Javascript? I was thinking of just using a global variable and using the pre and post events to update my items. Would this work? – Munsterlander Feb 01 '16 at 01:43
  • 1
    @Munsterlander Yes, you can use navigator's `prepop` or page's `hide`/ `destroy` to save data of the current page or update the view of the previous page. If you need it you can also use page's `show` event (of the previous page) to update the view if you didn't do it directly in the other events. 'prepop' event contains leavePage and enterPage objects so perhaps it's easier. – Fran Dios Feb 01 '16 at 02:53