I started from a demo Ionic app (ionic start myApp sidemenu
), and added a resolve
to 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 monitor rejected resolve
s here:
.run(function($ionicPlatform, $rootScope, $ionicLoading) {
$ionicPlatform.ready(function() {
// regular stuff here
$rootScope.$on('$stateChangeError', function() {
$ionicLoading.show({
template: 'All good!'
});
});
});
});
For some reason, if resolve
rejects immediately (see defer.reject()
above), the callback of $stateChangeError
is not run. If I do exactly the same, but outside of Ionic, it works!
Moreover, trying to delay the resolve
rejection by doing $timeout(defer.reject);
results in a different behaviour. Now it works in a browser as expected, but still doesn't work on a device. Trying to delay even more, results in success on device:
$timeout(function() {
defer.reject();
}, 250); // Doesn't work for me with 200 or less
Can anyone shed light on this?
SEE HERE HOW TO REPRODUCE THE ISSUE
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…