Ui-router solution behaves strangely in ionic

I started with the Ionic ( ionic start myApp sidemenu) demo application , and added resolveto one of the views :

resolve: {
  issue: function($q, $timeout) {
    var defer = $q.defer();
    //defer.reject();       // Doesn't work browser or device
    $timeout(defer.reject); // Works in browser, but not device
    return defer.promise;
  }
}

I track rejected resolvehere:

.run(function($ionicPlatform, $rootScope, $ionicLoading) {
  $ionicPlatform.ready(function() {
    // regular stuff here

    $rootScope.$on('$stateChangeError', function() {
      $ionicLoading.show({
        template: 'All good!'
      });
    });
  });
});

For some reason, if it is resolveimmediately rejected (see defer.reject()above), the callback $stateChangeErrordoes not start. If I do the same, but outside of Ionic, it works!

In addition, attempting to defer rejection resolveby performing $timeout(defer.reject);leads to different behavior. Now it works in the browser as expected, but still does not work on the device. Trying to delay even more leads to success on the device:

$timeout(function() {
  defer.reject();
}, 250); // Doesn't work for me with 200 or less

Can anyone shed some light on this?

,

+1
2

Angular . / , Angular JS - nextTick - $scope.apply(), .

$timeout $scope. $evalAsync - , $timeout, . , .

resolve: {
  issue: function($q, $timeout) {
    var defer = $q.defer();
    //defer.reject();       // <---- no nextTick
    $timeout(defer.reject); // <---- $timeout evaluates on nextTick
    return defer.promise;
  }
}

textTick $q.

, - , ! !

+1

1) $timeout 200

-, , $timeout (deferred.reject); , defered.reject , $timeout.

50, . http://plnkr.co/edit/6NXZEXrfz3WHVqoaRYJB?p=preview - 50 , , ! .

resolve: {
              test: function($q,  $timeout) {
                var defer = $q.defer(); 
                $timeout(function(){
                  defer.reject();
                },50);
                return defer.promise; 
              }
}

stateChangeError iconicPlatform.ready

2) $stateChangeError

, . , , ionicPlatform.ready(), , . starter , . , "".

UPDATED - ready() . , .

https://github.com/driftyco/ionic/issues/1751

+1

All Articles