Possible to trigger expression on opening sidemenu?


#1

Like the subject says really- when the sidemenu opens, either by clicking the sidebar-open icon or by dragging, is it possible to trigger an expression somehow?


#2

Yeah sure, we have isOpen for that.

if ($ionicSideMenuDelegate.isOpen(true)){
  //some code here
}

http://ionicframework.com/docs/api/service/$ionicSideMenuDelegate/


#3

That doesn’t seem to trigger when the sidemenu is opened… http://codepen.io/squrler/pen/FvbHh


#4

Any idea @mhartington?


#5

Looking into this, apparently this isn’t as straight forward as the docs made it seem :smile:


#6

Not sure why isOpen isn’t working, but this should get thing going.

  $scope.$watch(function () {
    return $ionicSideMenuDelegate.getOpenRatio();
  },
                function (ratio) {
                  if (ratio == 1){
                    alert("hey");
                  }
                });

#7

Thanks @mhartington! Does the trick :slight_smile:


#8

would it be possible to switch the ‘navicon’ with ‘X’ using this method? - i’m a little lost.

any help would be appreciated.


#9

Sure can


#10

Thank you so much for this, works perfectly. :slight_smile: