Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Onsen-UI using sliding menu with navigator

Ok, The problem is I have a working sliding menu with pages. Now one of my page has an ons-list. By clicking on ons-list-item I want to navigate to a new page with back button. I have searched everywhere but didn't find any proper solution to my problem. Here is my code.

<ons-sliding-menu
  menu-page="menu.html" main-page="home.html" side="left"
  var="menu" type="reveal" max-slide-distance="260px" swipable="true">
</ons-sliding-menu>

<ons-template id="menu.html">
  <ons-page modifier="menu-page">
    <ons-toolbar modifier="transparent"></ons-toolbar>

    <ons-list class="menu-list">
      <ons-list-item class="menu-item" ng-click="menu.setMainPage('home.html', {closeMenu: true})">
        <ons-icon icon="fa-plus"></ons-icon>
        Home
      </ons-list-item>

      <ons-list-item class="menu-item" ng-click="menu.setMainPage('browsehotels.html', {closeMenu: true})">
        <ons-icon icon="fa-bookmark"></ons-icon>
        Browse Hotels
      </ons-list-item>

    <ons-list-item class="menu-item" ng-click="menu.setMainPage('specialoffers.html', {closeMenu: true})">
        <ons-icon icon="fa-bookmark"></ons-icon>
        Special Offers <div class="notification menu-notification">3</div>
      </ons-list-item>        

      <ons-list-item class="menu-item" ng-click="menu.setMainPage('hoteldetails.html', {closeMenu: true})">
        <ons-icon icon="fa-bookmark"></ons-icon>
        Blog
      </ons-list-item>        

      <ons-list-item class="menu-item" ng-click="menu.setMainPage('hoteldetails.html', {closeMenu: true})">
        <ons-icon icon="fa-bookmark"></ons-icon>
        Bookings
      </ons-list-item>        

      <ons-list-item class="menu-item" ng-click="menu.setMainPage('hoteldetails.html', {closeMenu: true})">
        <ons-icon icon="fa-bookmark"></ons-icon>
        Contact Us
      </ons-list-item>        

    </ons-list>

  </ons-page>
</ons-template>

<ons-template id="home.html">
  <ons-page ng-controller="homeController">
    <ons-toolbar>
      <div class="left">
        <ons-toolbar-button ng-click="menu.toggle()">
          <ons-icon icon="ion-navicon" size="28px" fixed-width="false"></ons-icon>
        </ons-toolbar-button>
      </div>
      <div class="center">Some App with sliding menu</div>
      <div class="right">
        <ons-toolbar-button>
            <ons-icon icon="refresh" size="30px" spin="{{isFetching}}" fixed-width="true"></ons-icon>
        </ons-toolbar-button>
      </div>
    </ons-toolbar>

    <ons-list>
        <ons-list-item ng-click="Here I want to go to a whole new page">
             Some list item
        </ons-list-item>
    </ons-list>
  </ons-page>
</ons-template>
like image 543
Danish Jamil Avatar asked Mar 05 '15 12:03

Danish Jamil


1 Answers

You can use an <ons-navigator> as a child of your <ons-sliding-menu>:

<ons-template id="home.html">
  <ons-navigator var="myNav">
  <ons-page>
    <ons-toolbar>
    ...
       <ons-list-item ng-click="myNav.pushPage('newpage.html')">
    ...

Working here: http://codepen.io/frankdiox/pen/qEyvxB Anyway, doing this you should take care of the page stack. If you push a page but you "go back" using the menu instead of the back-button, the page created will remain in the stack.

In case you are interested, in Onsen UI's blog you have a tutorial where many ons elements are combined in a similar way. Hope it helps!

like image 141
Fran Dios Avatar answered Oct 06 '22 00:10

Fran Dios