Global functionality for all states


#1

Hello guys I was wonder if there is a way to make a global function that checks for Internet connection, that is called every time a state is being changed ?

Thnx in advance.


#2

Actually, @nicraboy has done a great job at demoing this.


#3

Thanks for the referral @mhartington!


#4

Hey guys I was talking about something else I already have function in the .run checking in it this way

if ( $cordovaNetwork.isOnline()==false ) {
  showmsg();
}



var showmsg= function() {
      var confirmPopup = $ionicPopup.confirm({
        title: 'Internet connection',
        template: 'Please turn on your internet and try again.',
        buttons: [
          { 
            text: 'Cancel',
            onTap: function() { ionic.Platform.exitApp();  }
          },
          {
            text: '<b>OK</b>',
            type: 'button-positive',
            onTap: function() { 
              if ($cordovaNetwork.isOnline()==false)  {
                 showmsg();   
               }
            }
          }
        ]
      });
    }

I thought that .run just runs once on start. And what happens if the user don’t have internet on the second tab for example.