Search code examples
javascripthtmlionic-frameworkhybrid-mobile-apphybrid

How do I get my ionic side menu button working?


I recently tried creating an ionic side menu. I had a problem where when I swiped the main body it opened up the menu. But I took the swipe function off and now I can't open the menu. I want to be able to click the navicon icon to be able to open the menu but don't know how to do it.

Here is the JavaScript:

.controller('TodoCtrl', function($scope, $timeout, $ionicModal, Projects, $ionicSideMenuDelegate) {


  $scope.toggleLeft = function() {
    $ionicSideMenuDelegate.toggleLeft();
  };

Here is the header code which contains the button:

<body ng-app="todo" ng-controller="TodoCtrl">
  <ion-side-menus>

  <!-- Center content -->
  <ion-side-menu-content>
  <ion-header-bar class="bar-dark">
  <button class="button button-icon button-clear ion-navicon" ng-click="toggleLeft()">
  </button>
  <h1 class="title">{{activeProject.title}}</h1>
  <!-- New Task button-->
  <button class="button button-icon" ng-click="newTask()">
    <i class="icon ion-compose"></i>
  </button>
</ion-header-bar>
<ion-content scroll="false">
<td-cards class="theLabel" id="card" ng-repeat="task in activeProject.tasks">
<td-card class="card-{{card.index}}">
<h4 style="text-align:center"> {{task.title}}</h4>
</td-card>
</td-cards>

Here is the menu content:

<ion-side-menu side="left">

      <ion-pane ion-side-menu-content drag-content="false">
           <ion-header-bar class="bar-dark">
               <h1 class="title">Cards</h1>
           </ion-header-bar>
           <ion-content scroll="true">
           <edge-drag-threshold="true" drag-content="true">
           </ion-content>
       </ion-pane> 

   </ion-side-menus>

Solution

  • Ionic has a handy menu-toggle directive to use so you can toggle the menu on a button like this.

    http://ionicframework.com/docs/api/directive/menuToggle/

    <ion-header-bar class="bar-dark">
      <button class="button button-icon button-clear ion-navicon" menu-toggle="left">
      </button>
      <h1 class="title">{{activeProject.title}}</h1>
      <!-- New Task button-->
      <button class="button button-icon" ng-click="newTask()">
        <i class="icon ion-compose"></i>
      </button>
    </ion-header-bar>