AngularJS OnsenUI reload parent page on nav.popPage() in child page

前端 未结 3 2012
深忆病人
深忆病人 2020-12-18 08:43

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 p

3条回答
  •  春和景丽
    2020-12-18 09:05

    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:

    $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);
    };
    

    You can create another function to encapsulate the replacing and popping, or just call them like:

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

    I am thinking of patching this into popPage() as an option (i.e. option.reloadPage) and submitting a pull request.

提交回复
热议问题