Skip to content

Commit 3d12853

Browse files
committed
fix(loading): options.hideOnStateChange: also hide on stateChangeError
Closes #3051.
1 parent 864b46a commit 3d12853

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

Diff for: js/angular/service/loading.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop,
7272
var loaderInstance;
7373
//default values
7474
var deregisterBackAction = noop;
75-
var deregisterStateListener = noop;
75+
var deregisterStateListener1 = noop;
76+
var deregisterStateListener2 = noop;
7677
var loadingShowDelay = $q.when();
7778

7879
return {
@@ -193,9 +194,11 @@ function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop,
193194
options = extend({}, $ionicLoadingConfig || {}, options || {});
194195
var delay = options.delay || options.showDelay || 0;
195196

196-
deregisterStateListener();
197+
deregisterStateListener1();
198+
deregisterStateListener2();
197199
if (options.hideOnStateChange) {
198-
deregisterStateListener = $rootScope.$on('$stateChangeSuccess', hideLoader);
200+
deregisterStateListener1 = $rootScope.$on('$stateChangeSuccess', hideLoader);
201+
deregisterStateListener2 = $rootScope.$on('$stateChangeError', hideLoader);
199202
}
200203

201204
//If loading.show() was called previously, cancel it and show with our new options
@@ -219,7 +222,8 @@ function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop,
219222
}
220223

221224
function hideLoader() {
222-
deregisterStateListener();
225+
deregisterStateListener1();
226+
deregisterStateListener2();
223227
$timeout.cancel(loadingShowDelay);
224228
getLoader().then(function(loader) {
225229
loader.hide();

Diff for: test/unit/angular/service/loading.unit.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ describe('$ionicLoading service', function() {
194194
}));
195195
});
196196

197-
it('should use options.hideOnStateChange', inject(function($ionicLoading, $rootScope, $timeout) {
197+
it('should use options.hideOnStateChange to hide on $stateChangeSuccess', inject(function($ionicLoading, $rootScope, $timeout) {
198198
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
199199
$ionicLoading.show({
200200
hideOnStateChange: true,
@@ -206,6 +206,18 @@ describe('$ionicLoading service', function() {
206206
expect(loader.hide).toHaveBeenCalled();
207207
}));
208208

209+
it('should use options.hideOnStateChange to hide on $stateChangeError', inject(function($ionicLoading, $rootScope, $timeout) {
210+
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
211+
$ionicLoading.show({
212+
hideOnStateChange: true,
213+
template: ''
214+
});
215+
spyOn(loader, 'hide');
216+
$rootScope.$broadcast('$stateChangeError');
217+
$rootScope.$apply();
218+
expect(loader.hide).toHaveBeenCalled();
219+
}));
220+
209221
it('should default false options.hideOnStateChange', inject(function($ionicLoading, $rootScope, $timeout) {
210222
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
211223
$ionicLoading.show({

0 commit comments

Comments
 (0)