monokh
monokh

Reputation: 1990

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.

Upvotes: 0

Views: 325

Answers (1)

Avijit Gupta
Avijit Gupta

Reputation: 5756

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

Upvotes: 1

Related Questions