mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(loading): options.hideOnStateChange: also hide on stateChangeError
Closes #3051.
This commit is contained in:
12
js/angular/service/loading.js
vendored
12
js/angular/service/loading.js
vendored
@@ -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();
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user