Adding an eventListener inside ionic


#1

Hey Guys,
first off all: I’m totaly new to ionic. Before i started with ionic and angular i only used jQuery so that all is a bit difficult for me right now.

I created an application for iOS which has a side menu. So now i have a button inside my application which toggles the side menu. As far as i understood the documentation, there is a possibilty to check, whether the menu is opened right now or closed right now.

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

I tried so much but i’m not able to figure out, how to detect the actual state via Javascript. I need a function, which i can call everywhere in my code which checks whether it is opened or closed. Can someone give me a hint or help me how to do this?

Thanks in advance!


#2

I made you a working example: http://plnkr.co/edit/XnFosA?p=preview

  setInterval(function(){ 
    console.log($ionicSideMenuDelegate.isOpen()); 
  }, 1000);

Open a console before you run this code.


#3

Gajotres, thank you so much.

console.log($ionicSideMenuDelegate.isOpen()); was all i needed!


#4

You’re wellcome :smile: