2

Hello i am working on onsen ui and have made a simple demo,it contains two pages page1 and page 2,my problem is i want to reload my page1 when i press ons-back-button from page2,as onsen ui maintains a pagestack,i cant do this,i searched a lot for this,but no luck,can anyone please help me how to do this?

my code is as below:

page1.html

    <ons-page ng-controller="listingController">

.
.
.

    </ons-page>

page2.html

<ons-page ng-controller="listingController">
    <ons-toolbar style="background: #da1e3e;" fixed-style>
        <div class="left">
            <ons-back-button >Back</ons-back-button>
        </div>
</ons-toolbar>
<ons-page>
JIGAR
  • 302
  • 2
  • 15

1 Answers1

1

In OnsenUI 2.0 there is a refresh parameter for popPage() to achieve this behavior, and there is already an issue to make a refresh-and-popPage from ons-back-button.

In OnsenUI 1.x you can refresh the previous page using one of these answers: AngularJS OnsenUI reload parent page on nav.popPage() in child page

Then, you can use ons-back-button style and call your popAndRefresh function:

<style>
  .ons-back-button__icon {
    vertical-align: top;
    font-size: 36px;
    margin-left: 8px;
    margin-right: 2px;
    width: 16px;
    display: inline-block;
    padding-top: 1px;
  }
</style>

<ons-toolbar-button class="toolbar-button--quiet" onclick="popAndRefresh()">
  <ons-icon class="ion-ios-arrow-back ons-back-button__icon"></ons-icon>
  Back
</ons-toolbar-button>
Fran Dios
  • 3,482
  • 2
  • 15
  • 26
  • Hello,i appreciate your guide,but its not acceptable answer,as i need to refresh it on back button provided by onsen not by using "poppage()" or customize a button to look like ons-back-button.can you tell me what code changes needed for this goal? – JIGAR Nov 20 '15 at 08:22
  • 1
    @FireCandy I don't understand, I just told you how to do it. Use the styles I provide to make a fake "ons-back-button" and trigger the custom popPage with it. – Fran Dios Nov 20 '15 at 09:29
  • No,Its not worthy as we have to maintain page stack manually.rite? which is very tedious.but if we are using onsen back button navigator page stack.So i just have seen that you commented on a post relates to my question.[onsen back press twice issue](http://stackoverflow.com/questions/28928418/error-navigatorviews-page-stack-is-empty-in-onsenui/28934444?noredirect=1#comment55411937_28934444) – JIGAR Nov 20 '15 at 09:55
  • You just need to copy one of the functions suggested in the question that I linked to and call it from the fake back-button I provided. Those functions modify the page stack "manually", yes, but what's the problem with it? You don't need to touch it anymore if you use them. If you think that's too much effort, then I am sorry but you cannot refresh the page. And I don't see how that post is related to your question apart from being 2 different issues of `ons-back-button`. – Fran Dios Nov 20 '15 at 10:11
  • nothing i also want to update onsen version but have no clue or idea.even cant understood your discussion with him. – JIGAR Nov 20 '15 at 10:27
  • He's trying to update to 1.x. You need 2.0-beta. I really think this answer offers a solution easier than updating to 2.0-beta. – Fran Dios Nov 20 '15 at 11:18
  • he is my colligue and i am also facing the same issue. – JIGAR Nov 20 '15 at 12:02
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/95698/discussion-between-firecandy-and-fran-dios). – JIGAR Nov 20 '15 at 12:43