Global functionality for all states


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.


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


Thanks for the referral @mhartington!


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

if ( $cordovaNetwork.isOnline()==false ) {

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)  {

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.