Search code examples
angularjsionic-frameworkionic-view

Ionic Side Menu on enter and leave (show / hide)


I'm trying to listen to when ionic-side-menu are opened and closed. To do this I am attaching the $ionicView.enter and $ionicView.leave like so:

$scope.$on('$ionicView.leave', function(){
  console.log('leave called');
});

$scope.$on('$ionicView.enter', function(){
  console.log('enter called');
});

Using this code $ionicView.enter is called once when the app loads and never again when toggling the menu. $ionicView.leave also never gets called.


Solution

  • You can use $ionicSideMenuDelegate.isOpen() to keep track of opening and closing of the side menu:

    $scope.$watch(function() { return $ionicSideMenuDelegate.isOpen(); }, function(isOpen) {
        if (isOpen) {
            // Menu Opened
        }
        else {
            // Menu Closed
        }
    });
    

    Reference: https://github.com/driftyco/ionic/issues/1437