mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
feat($ionicLoading): add $ionicLoadingConfig constant for default options
Closes #1800
This commit is contained in:
@@ -360,6 +360,13 @@
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="{{ page.versionHref }}/api/object/$ionicLoadingConfig/">
|
||||
$ionicLoadingConfig
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
28
js/angular/service/loading.js
vendored
28
js/angular/service/loading.js
vendored
@@ -32,8 +32,32 @@ var LOADING_SET_DEPRECATED = '$ionicLoading instance.setContent() has been depre
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
/**
|
||||
* @ngdoc object
|
||||
* @name $ionicLoadingConfig
|
||||
* @module ionic
|
||||
* @description
|
||||
* Set the default options to be passed to the {@link ionic.service:$ionicLoading} service.
|
||||
*
|
||||
* @usage
|
||||
* ```js
|
||||
* var app = angular.module('myApp', ['ionic'])
|
||||
* app.constant('$ionicLoadingConfig', {
|
||||
* template: 'Default Loading Template...'
|
||||
* });
|
||||
* app.controller('AppCtrl', function($scope, $ionicLoading) {
|
||||
* $scope.showLoading = function() {
|
||||
* $ionicLoading.show(); //options default to values in $ionicLoadingConfig
|
||||
* };
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
IonicModule
|
||||
.constant('$ionicLoadingConfig', {
|
||||
template: '<i class="ion-loading-d"></i>'
|
||||
})
|
||||
.factory('$ionicLoading', [
|
||||
'$ionicLoadingConfig',
|
||||
'$document',
|
||||
'$ionicTemplateLoader',
|
||||
'$ionicBackdrop',
|
||||
@@ -42,7 +66,7 @@ IonicModule
|
||||
'$log',
|
||||
'$compile',
|
||||
'$ionicPlatform',
|
||||
function($document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q, $log, $compile, $ionicPlatform) {
|
||||
function($ionicLoadingConfig, $document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q, $log, $compile, $ionicPlatform) {
|
||||
|
||||
var loaderInstance;
|
||||
//default values
|
||||
@@ -151,7 +175,7 @@ function($document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q, $log, $c
|
||||
}
|
||||
|
||||
function showLoader(options) {
|
||||
options || (options = {});
|
||||
options = extend($ionicLoadingConfig || {}, options || {});
|
||||
var delay = options.delay || options.showDelay || 0;
|
||||
|
||||
//If loading.show() was called previously, cancel it and show with our new options
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
describe('$ionicLoading service', function() {
|
||||
beforeEach(module('ionic'));
|
||||
beforeEach(module('ionic', function($provide) {
|
||||
//Set default options to blank for the sake of tests
|
||||
$provide.constant('$ionicLoadingConfig', {});
|
||||
}));
|
||||
it('should reuse loader instance for getLoader', inject(function($ionicLoading) {
|
||||
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
|
||||
var loader2 = TestUtil.unwrapPromise($ionicLoading._getLoader());
|
||||
@@ -189,5 +192,29 @@ describe('$ionicLoading service', function() {
|
||||
expect(deregisterSpy).toHaveBeenCalled();
|
||||
}));
|
||||
});
|
||||
});
|
||||
describe('$ionicLoadingConfig', function() {
|
||||
beforeEach(module('ionic', function($provide) {
|
||||
$provide.constant('$ionicLoadingConfig', {
|
||||
template: 'some template'
|
||||
});
|
||||
}));
|
||||
|
||||
it('should use $ionicLoadingConfig options by default', inject(function($ionicLoading, $timeout) {
|
||||
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
|
||||
$ionicLoading.show();
|
||||
$timeout.flush();
|
||||
expect(loader.element.text()).toBe('some template');
|
||||
}));
|
||||
|
||||
it('should allow override', inject(function($ionicLoading, $timeout) {
|
||||
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
|
||||
$ionicLoading.show({
|
||||
template: 'some other template'
|
||||
});
|
||||
$timeout.flush();
|
||||
expect(loader.element.text()).toBe('some other template');
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user