fix(loading): options.hideOnStateChange: also hide on stateChangeError

Closes #3051.
This commit is contained in:
Andrew
2015-02-26 14:02:39 -07:00
parent 864b46aa81
commit 3d12853593
2 changed files with 21 additions and 5 deletions

View File

@@ -72,7 +72,8 @@ function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop,
var loaderInstance;
//default values
var deregisterBackAction = noop;
var deregisterStateListener = noop;
var deregisterStateListener1 = noop;
var deregisterStateListener2 = noop;
var loadingShowDelay = $q.when();
return {
@@ -193,9 +194,11 @@ function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop,
options = extend({}, $ionicLoadingConfig || {}, options || {});
var delay = options.delay || options.showDelay || 0;
deregisterStateListener();
deregisterStateListener1();
deregisterStateListener2();
if (options.hideOnStateChange) {
deregisterStateListener = $rootScope.$on('$stateChangeSuccess', hideLoader);
deregisterStateListener1 = $rootScope.$on('$stateChangeSuccess', hideLoader);
deregisterStateListener2 = $rootScope.$on('$stateChangeError', hideLoader);
}
//If loading.show() was called previously, cancel it and show with our new options
@@ -219,7 +222,8 @@ function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop,
}
function hideLoader() {
deregisterStateListener();
deregisterStateListener1();
deregisterStateListener2();
$timeout.cancel(loadingShowDelay);
getLoader().then(function(loader) {
loader.hide();

View File

@@ -194,7 +194,7 @@ describe('$ionicLoading service', function() {
}));
});
it('should use options.hideOnStateChange', inject(function($ionicLoading, $rootScope, $timeout) {
it('should use options.hideOnStateChange to hide on $stateChangeSuccess', inject(function($ionicLoading, $rootScope, $timeout) {
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
$ionicLoading.show({
hideOnStateChange: true,
@@ -206,6 +206,18 @@ describe('$ionicLoading service', function() {
expect(loader.hide).toHaveBeenCalled();
}));
it('should use options.hideOnStateChange to hide on $stateChangeError', inject(function($ionicLoading, $rootScope, $timeout) {
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
$ionicLoading.show({
hideOnStateChange: true,
template: ''
});
spyOn(loader, 'hide');
$rootScope.$broadcast('$stateChangeError');
$rootScope.$apply();
expect(loader.hide).toHaveBeenCalled();
}));
it('should default false options.hideOnStateChange', inject(function($ionicLoading, $rootScope, $timeout) {
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
$ionicLoading.show({