3

Suppose I've 2 controllers - C1 and C2. I do a navigator.pushPage from v1.html to v2.html. And then I do a navigator.popPage on v2.html. But the popPage doesn't reload the controller C1. I'm trying to figure out a way to reload the controller, but have not been able to do that. I tried with popPage({refresh:true}) also, but that didn't help either. Here's the codepen: http://codepen.io/rohit_jain/pen/eNbyEm.

Is there any way I can achieve what I want?

Here's the real example:

On v1.html, I'm displaying the Cart details - total_cart_items or total_price. There I've a button to move to v2.html, where I display Cart contents. On v2.html, the person can reset the cart, and then go back to page v1.html. Now, I want the reset cart action to change total_cart_items and total_price on v1.html. But that's not happening.

Rohit Jain
  • 209,639
  • 45
  • 409
  • 525
  • Are you trying to reset certain models in the controller by reloading it ?? Why not call a second method for that in the ng-click itself .. – Manish Kr. Shukla Aug 05 '15 at 05:47
  • @Rohit, the first page keeps being in the stack, with the relative controller. Why do you want to reload it? – Andi Pavllo Aug 05 '15 at 06:04
  • @AndiPavllo Because I'm modifying the service variable in second controller, and then popping back. I want the changes to be reflected back in controller 1 view. – Rohit Jain Aug 05 '15 at 06:11
  • @ManishKr.Shukla Sorry, I didn't get you? – Rohit Jain Aug 05 '15 at 06:13
  • `refresh: true` is only in master branch, not released yet. Meanwhile, one of these answers may help you: http://stackoverflow.com/questions/29470198/angularjs-onsenui-reload-parent-page-on-nav-poppage-in-child-page/ – Fran Dios Aug 05 '15 at 06:29
  • @FranDios I went through that question earliers. I tried with your approach there, but there is slight glitch in navigation, when I do a `replacePage`. – Rohit Jain Aug 05 '15 at 06:31
  • If by resetting the controller, you're actually trying to reset data values in that controller, you can do so by calling another method after popage, in the ng-click attribute. – Manish Kr. Shukla Aug 05 '15 at 06:31
  • @ManishKr.Shukla Yes I can do, but the changes will not get reflected in first controller, unless we reload it. – Rohit Jain Aug 05 '15 at 06:32
  • @RohitJain I just saw your comment in the other question. As I said there, you can try with the other answer and see if it works for you. – Fran Dios Aug 05 '15 at 06:32
  • @FranDios Ok, the other answer did work.. But it's a bit ugly. I've to explicitly pass the previous page I want to replace :( – Rohit Jain Aug 05 '15 at 06:38
  • @RohitJain I think we will add the `refresh` feature to the next release (1.3.9) since many people is asking for it :) – Fran Dios Aug 05 '15 at 06:44
  • @FranDios :( And is the release planned anytime soon? – Rohit Jain Aug 05 '15 at 06:57
  • @RohitJain I believe within 2 weeks! – Fran Dios Aug 06 '15 at 02:11

1 Answers1

0

You can achieve it using nav.resetToPage(page, options) function, which clears the page stack and add the specified page to the new stack. The options parameter corresponds to the navigator.pushPage API.

Andi Pavllo
  • 2,506
  • 4
  • 18
  • 30