Disable swipe to view sidemenu when using tabs

All we need is an easy explanation of the problem, so here it is.

I’m writing a small ionic app and have an issue. I’m using a sidemenu and also tabs. I have an ionic slide-box in one of my views, when I wipe this slidebox from left to right the side menu slides out. I’ve read through various related topics on the ionic forum but none have worked.

I’ve tried adding drag-content="false" to various tags and also added $ionicSideMenuDelegate.canDragContent(false); to my controller.

Neither worked. I think it’s because I’m using a sidemenu, with tabs and views in the tabs. Heres my code:

index.html

    <ion-side-menus>

    <!-- Header bar -->
    <ion-side-menu-content ng-controller="NavCtrl" drag-content="false">
        <ion-nav-bar class="bar-positive">
            <ion-nav-back-button class="button-icon ion-ios7-arrow-back">
            </ion-nav-back-button>
        </ion-nav-bar>

        <!-- Page content -->
        <ion-nav-view drag-content="false" animation="slide-left-right"></ion-nav-view>
    </ion-side-menu-content> 

    <!-- Side menu -->
    <ion-side-menu side="left" class="side-menu">
        <ion-header-bar class="bar bar-header bar-dark">
            <h1 class="title">Menu</h1>
        </ion-header-bar>
        <ion-content has-header="true">

            <div ng-if="authData.twitter" class="logged-in-user item item-avatar">
                <img ng-src="{{authData.twitter.cachedUserProfile.profile_image_url}}"/>
                <h2>Hello, {{authData.twitter.displayName}}</h2>
                <p>Logged in via Twitter</p>
            </div>

            <div ng-if="authData.facebook" class="logged-in-user item item-avatar">
                <img ng-src="{{authData.facebook.cachedUserProfile.picture.data.url}}"/>
                <h2>Hello, {{authData.facebook.displayName}}</h2>
                <p>Logged in via Facebook</p>
            </div>

            <ul class="list">
                <li>
                    <a class="item item-icon-left" menu-close nav-clear href="#/venue" rel="nofollow noreferrer noopener">
                        <i class="icon ion-ios7-location"></i>Venue
                    </a>
                </li>
                <li>
                    <a class="item item-icon-left" menu-close nav-clear href="#/lunch" rel="nofollow noreferrer noopener">
                        <i class="icon ion-pizza"></i>Lunch
                    </a>
                </li>
                <li>
                    <a class="item item-icon-left" menu-close nav-clear href="#/wifi" rel="nofollow noreferrer noopener">
                        <i class="icon ion-wifi"></i>Wifi
                    </a>
                </li>
            </ul>
        </ion-content>
        <ion-footer-bar class="bar bar-dark">
            <button class="button button-icon icon ion-log-out menu-close nav-clear" ng-controller="LoginCtrl" ng-click="logout()"> Logout</button>
        </ion-footer-bar>
    </ion-side-menu>  

  </ion-side-menus>

and my view:

<ion-view title="Agenda">
<ion-content drag-content="false">
    <ion-slide-box on-slide-changed="slideHasChanged($index)">
        <ion-slide>
            <div class="header-card header-card--image">
                <div class="overlay">
                    <div class="item item-text-wrap">
                        <h3 class="header-card__heading">Happening now</h3>
                        <img ng-src="img/me.jpeg" class="header-card__avatar"/>
                        <h2 class="header-card__heading">some guy</h2>
                        <p class="header-card__text">Some title</p>
                    </div>
                </div>
            </div>
        </ion-slide>
        <ion-slide>
            <div class="header-card header-card--image">
                <div class="overlay">
                    <div class="item item-text-wrap">
                        <h3 class="header-card__heading">Coming Next</h3>
                        <img ng-src="img/me.jpeg" class="header-card__avatar"/>
                        <h2 class="header-card__heading">Some guy</h2>
                        <p class="header-card__text">Slowly taking over the world</p>
                    </div>
                </div>
            </div>
        </ion-slide>
    </ion-slide-box>
    <ion-list>
        <ion-item ng-repeat="(id,agendaItem) in agendaItems" type="item-text-wrap" href="#/tab/agendaItem/{{agendaItem.$id}}" rel="nofollow noreferrer noopener" class="item item-avatar item-with-grid">
            <img ng-src="{{agendaItem.image}}">
            <p>{{agendaItem.startTime}} <i ng-if="agendaItem.hasNotificationSet == true" class="icon-left ion-ios7-bell"></i></p>
            <h2>{{agendaItem.title}}</h2>
            <p>{{agendaItem.speaker}}</p>
            <ion-option-button ng-class="agendaItem.hasNotificationSet ? 'button-balanced icon ion-ios7-bell' : 'button-positive icon ion-ios7-bell-outline'" ng-controller="NotificationCtrl" ng-click="add(agendaItem)"></ion-option-button>

            <!--<ion-option-button ng-click="getNotificationIds()"></ion-option-button>-->
        </ion-item>
    </ion-list>
</ion-content>

and my controller:

.controller('AgendaCtrl', function($scope, AgendaFactory, $ionicSideMenuDelegate, $rootScope, $ionicPopup, $timeout, $cordovaLocalNotification, NotificationFactory) {

    $ionicSideMenuDelegate.canDragContent(false); // doesn't seem to work

    var agendaItems = AgendaFactory.getAgenda();

    // Loop through agenda itens and check which have notifications set
    agendaItems.$loaded().then(function(array) {
        angular.forEach(array, function(value, key) {

        if (NotificationFactory.isNotificationScheduled(value.notificationId) == true) {
                value.hasNotificationSet = true;
        } else {
                value.hasNotificationSet = false;
        }

    });

    $scope.getNotificationIds = function () {
        $cordovaLocalNotification.getScheduledIds().then(function (scheduledIds) {
          console.log(scheduledIds);
        });
      };

        $scope.agendaItems = agendaItems;
    });

    $scope.firstTimeLogin = $rootScope.firstTimeLogin;

})

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

I’m using something like this on my app:

.controller('AgendaCtrl', function($scope, $ionicSideMenuDelegate){
  $scope.$on('$ionicView.enter', function(){
      $ionicSideMenuDelegate.canDragContent(false);
    });
  $scope.$on('$ionicView.leave', function(){
      $ionicSideMenuDelegate.canDragContent(true);
    });
})

now, when you leave the view it’s draggable again.

Method 2

ion-side-menu-content drag-content="false" put this code in your ion-sidemenu‘s ion-pane tag

Method 3

<ion-side-menus>
  <ion-side-menu-content drag-content="false">
  ............
  </ion-side-menu-content>
</ion-side-menus>

this is sample code follow @Chetan Buddh’s answer

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply