mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
14
js/angular/service/loading.js
vendored
14
js/angular/service/loading.js
vendored
@@ -66,11 +66,13 @@ IonicModule
|
||||
'$log',
|
||||
'$compile',
|
||||
'$ionicPlatform',
|
||||
function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q, $log, $compile, $ionicPlatform) {
|
||||
'$rootScope',
|
||||
function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q, $log, $compile, $ionicPlatform, $rootScope) {
|
||||
|
||||
var loaderInstance;
|
||||
//default values
|
||||
var deregisterBackAction = angular.noop;
|
||||
var deregisterStateListener = angular.noop;
|
||||
var loadingShowDelay = $q.when();
|
||||
|
||||
return {
|
||||
@@ -84,6 +86,8 @@ function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop,
|
||||
* - `{string=}` `templateUrl` The url of an html template to load as the content of the indicator.
|
||||
* - `{object=}` `scope` The scope to be a child of. Default: creates a child of $rootScope.
|
||||
* - `{boolean=}` `noBackdrop` Whether to hide the backdrop. By default it will be shown.
|
||||
* - `{boolean=}` `hideOnStateChange` Whether to hide the loading spinner when navigating
|
||||
* to a new state. Default false.
|
||||
* - `{number=}` `delay` How many milliseconds to delay showing the indicator. By default there is no delay.
|
||||
* - `{number=}` `duration` How many milliseconds to wait until automatically
|
||||
* hiding the indicator. By default, the indicator will be shown until `.hide()` is called.
|
||||
@@ -115,10 +119,8 @@ function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop,
|
||||
$ionicTemplateLoader.load(options.templateUrl) :
|
||||
//options.content: deprecated
|
||||
$q.when(options.template || options.content || '');
|
||||
|
||||
|
||||
self.scope = options.scope || self.scope;
|
||||
|
||||
self.scope = options.scope || self.scope;
|
||||
|
||||
if (!this.isShown) {
|
||||
//options.showBackdrop: deprecated
|
||||
@@ -198,6 +200,9 @@ function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop,
|
||||
loadingShowDelay = $timeout(angular.noop, delay);
|
||||
|
||||
loadingShowDelay.then(getLoader).then(function(loader) {
|
||||
if (options.hideOnStateChange) {
|
||||
deregisterStateListener = $rootScope.$on('$stateChangeSuccess', hideLoader);
|
||||
}
|
||||
return loader.show(options);
|
||||
});
|
||||
|
||||
@@ -215,6 +220,7 @@ function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop,
|
||||
}
|
||||
|
||||
function hideLoader() {
|
||||
deregisterStateListener();
|
||||
$timeout.cancel(loadingShowDelay);
|
||||
getLoader().then(function(loader) {
|
||||
loader.hide();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
describe('$ionicLoading service', function() {
|
||||
ddescribe('$ionicLoading service', function() {
|
||||
beforeEach(module('ionic', function($provide) {
|
||||
//Set default options to blank for the sake of tests
|
||||
$provide.constant('$ionicLoadingConfig', {});
|
||||
@@ -193,6 +193,32 @@ describe('$ionicLoading service', function() {
|
||||
expect(deregisterSpy).toHaveBeenCalled();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should use options.hideOnStateChange', inject(function($ionicLoading, $rootScope, $timeout) {
|
||||
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
|
||||
$ionicLoading.show({
|
||||
hideOnStateChange: true,
|
||||
template: ''
|
||||
});
|
||||
spyOn(loader, 'hide');
|
||||
$timeout.flush();
|
||||
$rootScope.$broadcast('$stateChangeSuccess');
|
||||
$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({
|
||||
template: ''
|
||||
});
|
||||
spyOn(loader, 'hide');
|
||||
$timeout.flush();
|
||||
$rootScope.$broadcast('$stateChangeSuccess');
|
||||
$rootScope.$apply();
|
||||
expect(loader.hide).not.toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
});
|
||||
describe('$ionicLoadingConfig', function() {
|
||||
beforeEach(module('ionic', function($provide) {
|
||||
|
||||
Reference in New Issue
Block a user