AngularJS OnsenUI reloads parent page on nav.popPage () on child page

I call the function on ng-init, and on this page I click on the new page on the "Navigator" page with a button. And on the child page, I display the current page. Now I want to reload the parent page when the child page is removed from the 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 restart the application with

window.location.reload(true);
+4
source share
3 answers

pageReplace(), Onsen UI 1.3.0. popPage() :

$scope.popAndReplace = function() {
  $scope.nav.popPage({onTransitionEnd : function() {
     $scope.nav.replacePage('page1.html', { animation : 'none' } );
  }})
};

: http://codepen.io/frankdiox/pen/gbJGZw

, !

+2

, /, . , insertPage() . :

$scope.replacePreviousPage = function(url) {
      var pages = $scope.nav.getPages(),
          index = pages.length - 2;

      if (index < 0)
          return;

      $scope.nav.insertPage(index, url);
      pages.splice(index, 1);
};

:

$scope.replacePreviousPage('views/page1.html');
$scope.nav.popPage();

popPage() (.. option.reloadPage) .

+4

danjarvis,

! Onsen , . , , - . , . , .

//function to go back and reload controller
$rootScope.index = 0;
$rootScope.replacePreviousPage = function (url) {
    var c = 0;
    angular.forEach(nav.getPages(), function (v, i) {
        if (i >= $rootScope.index) {
            nav.getPages()[i].destroy();
            c++;
        }
    });
    nav.insertPage($rootScope.index, url);
    nav.popPage();
};

//back
$rootScope.back = function (page) {
    if (page === "index") {
        location.reload();
    } else {
        if (page === "version") {
            $rootScope.index = $rootScope.index - 2;
        } else {
            $rootScope.index--;
        }
        $rootScope.replacePreviousPage('templates/' + page + '.html');
    }
};

//forward
$rootScope.forward = function (page) {
    nav.pushPage('templates/' + page + '.html');
    $rootScope.index++;
};
+1

All Articles