3

I have a js object loaded on one Onsen UI masterpage, when I called ons.navigator.pushPage('child_page.html') how can I get the js object on the child page?

mehdi lotfi
  • 11,194
  • 18
  • 82
  • 128
Eli
  • 99
  • 1
  • 8

2 Answers2

8

See the documentation and guides.

http://onsenui.io/guide/overview.html#PageNavigation

You can get objects via the following methods:

page1

myNavigator.pushPage("page2.html", { param1: "value1", param2: "value2" });

page2

var page = myNavigator.getCurrentPage();
console.log(page.options.param1); // Will return "value1"    
Ataru
  • 544
  • 4
  • 7
  • I am having the same issue,and i used this answer working perfect but only for one parameter passing,When i am trying to pass second parameter it is not working. – Jigar Makwana Oct 20 '15 at 11:22
  • Note this is the answer for OnsenUI version 1. For Version 2 see the answer by @morteza_tourani below. The link given in this answer by Ataru does not work anymore. – pashute Jul 29 '17 at 19:57
5

In OnsenUI 2 you can access like this:

var options = myNavigator.topPage.pushedOptions;

I tried ataru's answer but didn't work for me, I think this is because of the RC Version hope they fix this or at least change their documentation about it.

Community
  • 1
  • 1
Morteza Tourani
  • 3,506
  • 5
  • 41
  • 48
  • I use `var nav = document.querySelector('#navigator');` I can then do `nav.popPage()` but there is no attribute `nav.topPage`!! I see only THIS page's pushedOptions which are `animation` related. What am I doing wrong? – pashute Jul 27 '17 at 13:27
  • @pashute My answer is for long time ago when I tried `Onsen` for a while, but now I'm using `Ionic` due to company policies and since that moment forward `Onsen` has taken lot's of great steps. All I told means I'm not a good one to ask anymore and I'm sorry. – Morteza Tourani Jul 27 '17 at 14:15
  • It seems I had some mistake in the code, that caused the nav not to evaluate. So your answer did in fact work for me. Thanks so much!! (I upvoted your answer) – pashute Jul 29 '17 at 19:49