I'm calling a function on ng-init and in that page I'm pushing a new page to the pageStack of navigator on a button click. And in the child page I'm popping the current page. Now I want to reload the parent page when the child page is removed from page stack.
Here is the code:
HTML
<ons-navigator var="nav" page="page1.html">
</ons-navigator>
<ons-template id="page1.html">
<ons-page ng-controller="pageOneController" ng-init="reload()">
<ons-toolbar>
<div class="center">Page 1</div>
</ons-toolbar>
<ons-button ng-click="nav.pushPage('page2.html')">Push Page</ons-button>
</ons-page>
</ons-template>
<ons-template id="page2.html">
<ons-page>
<ons-toolbar>
<div class="center">Page 2</div>
</ons-toolbar>
<ons-button ng-click="nav.popPage();">Pop Page</ons-button>
</ons-page>
</ons-template>
AngularJS
module.controller('pageOneController', function(){
$scope.reload = function(){
console.log('Page one controller reloaded');
}
});
Update
one solution is to reload the app by using
window.location.reload(true);
While Fran's answer works great, there is a small flicker / hiccup in the UI when the page gets replaced. I took a slightly different approach by using
insertPage()
and changing the order of ops. The end result is smoother UI flow:You can create another function to encapsulate the replacing and popping, or just call them like:
I am thinking of patching this into
popPage()
as an option (i.e.option.reloadPage
) and submitting a pull request.You can use the new
pageReplace()
that comes with the new Onsen UI 1.3.0. You can pass it to the callback ofpopPage()
like this:Working here: http://codepen.io/frankdiox/pen/gbJGZw
Hope it helps!
danjarvis,
Thank you for the idea! I was struggling with Onsen coming from Ionic, so your example really helped. I slightly modified it and here is an alternative if anyone was interested. It wasn't destroying ons-pages for me, which I needed it to for handling some odd duplicate directive issues. Also, I had to go back more than one page sometimes.