Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49185

$state.go() not working

$
0
0

@priteshpmehta wrote:

Hi,

In my app i am checking network state whether user is online or offline using $cordovaNetwork on each request. If user doesn't have network or if any user goes offline then i want to send user on some other page (other controller). Once user comes back online automatically or by clicking retry button, app should redirect to previous controller again.

I have tried following code but it works only when user goes offline... once he comes online again... it went through it...even it print console log but $state.go() is not working...

.controller('MasterController',['$scope', '$state', '$rootScope', '$cordovaNetwork', function ($scope, $state, $rootScope, $cordovaNetwork) {

 document.addEventListener("deviceready", function () {

    var type = $cordovaNetwork.getNetwork()

    var isOnline = $cordovaNetwork.isOnline()

    var isOffline = $cordovaNetwork.isOffline()

    // listen for Offline event
    $rootScope.$on('$cordovaNetwork:offline', function(event, networkState){
      var offlineState = networkState;
      console.log("offlineState : " + offlineState);
      $state.go('mainMaster.Offline', {}, {reload: true});
    })

  }, false);
}])


.controller('OfflineController',['$scope', '$state', '$rootScope', '$cordovaNetwork', function ($scope, $state, $rootScope, $cordovaNetwork) {

    document.addEventListener("deviceready", function () {

      var type = $cordovaNetwork.getNetwork()

      var isOnline = $cordovaNetwork.isOnline()

      var isOffline = $cordovaNetwork.isOffline()

      // listen for Online event
      $rootScope.$on('$cordovaNetwork:online', function(event, networkState){
        var onlineState = networkState;
        // i am able to get following log... but $state.go not working..
        console.log("onlineState : " + onlineState);
        $state.go('mainMaster.Dashboard', {}, {reload: true});
      })


    }, false);
}])

Thank you.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49185

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>