如何让离子侧菜单按钮工作?

时间:2014-11-04 13:40:12

标签: javascript html ionic-framework hybrid-mobile-app hybrid

我最近尝试创建离子侧菜单。我有一个问题,当我刷主体时打开菜单。但是我关闭了滑动功能,现在我无法打开菜单。我希望能够单击导航图标以便能够打开菜单但不知道如何操作。

以下是JavaScript:

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


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

以下是包含按钮的标题代码:

<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>

以下是菜单内容:

<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>

3 个答案:

答案 0 :(得分:3)

Ionic有一个方便的menu-toggle指令可以使用,所以你可以在这样的按钮上切换菜单。

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>

答案 1 :(得分:2)

在index.html中,将menu-toggle="left"替换为ng-click="toggleProjects()",并在app.js中添加此

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

答案 2 :(得分:1)

以下是我的工作:

<ion-header-bar class="bar-dark">
  <button class="button button-icon" ng-click="toggleSideMenu()">
    <i class="icon ion-navicon"></i>
  </button>
  <h1 class="title">{{ activeProject.title }}</h1>
</ion-header-bar>

app.js 中,选中$ionicSideMenuDelegate.isOpen()

$scope.toggleSideMenu = function() {
  if ($ionicSideMenuDelegate.isOpen()) {
    $ionicSideMenuDelegate.toggleLeft(false); // close
  } else {
    $ionicSideMenuDelegate.toggleLeft(); // open
  }
};