Side menu click to body closes menu



I am working with Ionic for some time now and wanted to thank the creators. Great Job!

I am using an slidebox with an side menu.
When the menu is open it should not be possible to slide the slide box.
So i am using $ionicSlideBoxDelegate enableSlide = !enableSlide in the toggleLeft function to deactivate/activate the slide. Works as it should.

My problem now is that the menu is closed by clicking on the document body without using the toggle function.
So in this case the “enable slide” stays on “false”. The Menu is closed and the Slidebox not slideable.

How can i trigger a enableSlide toggle whenever the sidemenu is closed or opened? Is there an .on event for the side menu?

Where is the function which toggles the side menu on a body click?

Thank you in advance !!



You could check this with a watch and trigger on change on the value exposed by the side menu delegate :wink:

If you look at the documentation, you can see that the ionicsidemenudelegate exposes some methods,$ionicSideMenuDelegate/ . Assuming you have a left side menu, you could watch for a change on $ionicSideMenuDelegate.isOpenLeft();

Put the following code in your controller:

$scope.$watch(function() { 
      return $ionicSideMenuDelegate.isOpenLeft();
      function(isOpenLeft) {
        if( isOpenLeft ) {
             alert('left side menu is now open');
        } else {
             alert('side menu is now closed');

Firstly, “$watch” takes two functions as an argument. If the return value for the first function changes, the second function will be fired. The isOpenLeft only return true or false, so the second function will only fire when the state changes! The second function will be executed with the return value of the first function, so you can read the value there without doing another call to the ionicsidemenudelegate :slight_smile: Hope this helps!


Thank you! That works nice!


$watch function executed repeatedly and slide menu stuck between slide menu and controller.
Is there any event that should emit after close or open menu ?