Skip to content

Commit 26ca840

Browse files
committed
feat($ionicLoading): add $ionicLoadingConfig constant for default options
Closes #1800
1 parent 7e20424 commit 26ca840

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

Diff for: config/docs/templates/api_menu_version.template.html

+7
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,13 @@
360360
</a>
361361
</li>
362362
</ul>
363+
<ul>
364+
<li>
365+
<a href="{{ page.versionHref }}/api/object/$ionicLoadingConfig/">
366+
$ionicLoadingConfig
367+
</a>
368+
</li>
369+
</ul>
363370
</li>
364371

365372

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

+26-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,32 @@ var LOADING_SET_DEPRECATED = '$ionicLoading instance.setContent() has been depre
3232
* });
3333
* ```
3434
*/
35+
/**
36+
* @ngdoc object
37+
* @name $ionicLoadingConfig
38+
* @module ionic
39+
* @description
40+
* Set the default options to be passed to the {@link ionic.service:$ionicLoading} service.
41+
*
42+
* @usage
43+
* ```js
44+
* var app = angular.module('myApp', ['ionic'])
45+
* app.constant('$ionicLoadingConfig', {
46+
* template: 'Default Loading Template...'
47+
* });
48+
* app.controller('AppCtrl', function($scope, $ionicLoading) {
49+
* $scope.showLoading = function() {
50+
* $ionicLoading.show(); //options default to values in $ionicLoadingConfig
51+
* };
52+
* });
53+
* ```
54+
*/
3555
IonicModule
56+
.constant('$ionicLoadingConfig', {
57+
template: '<i class="ion-loading-d"></i>'
58+
})
3659
.factory('$ionicLoading', [
60+
'$ionicLoadingConfig',
3761
'$document',
3862
'$ionicTemplateLoader',
3963
'$ionicBackdrop',
@@ -42,7 +66,7 @@ IonicModule
4266
'$log',
4367
'$compile',
4468
'$ionicPlatform',
45-
function($document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q, $log, $compile, $ionicPlatform) {
69+
function($ionicLoadingConfig, $document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q, $log, $compile, $ionicPlatform) {
4670

4771
var loaderInstance;
4872
//default values
@@ -151,7 +175,7 @@ function($document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q, $log, $c
151175
}
152176

153177
function showLoader(options) {
154-
options || (options = {});
178+
options = extend($ionicLoadingConfig || {}, options || {});
155179
var delay = options.delay || options.showDelay || 0;
156180

157181
//If loading.show() was called previously, cancel it and show with our new options

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

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
describe('$ionicLoading service', function() {
2-
beforeEach(module('ionic'));
2+
beforeEach(module('ionic', function($provide) {
3+
//Set default options to blank for the sake of tests
4+
$provide.constant('$ionicLoadingConfig', {});
5+
}));
36
it('should reuse loader instance for getLoader', inject(function($ionicLoading) {
47
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
58
var loader2 = TestUtil.unwrapPromise($ionicLoading._getLoader());
@@ -189,5 +192,29 @@ describe('$ionicLoading service', function() {
189192
expect(deregisterSpy).toHaveBeenCalled();
190193
}));
191194
});
195+
});
196+
describe('$ionicLoadingConfig', function() {
197+
beforeEach(module('ionic', function($provide) {
198+
$provide.constant('$ionicLoadingConfig', {
199+
template: 'some template'
200+
});
201+
}));
202+
203+
it('should use $ionicLoadingConfig options by default', inject(function($ionicLoading, $timeout) {
204+
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
205+
$ionicLoading.show();
206+
$timeout.flush();
207+
expect(loader.element.text()).toBe('some template');
208+
}));
209+
210+
it('should allow override', inject(function($ionicLoading, $timeout) {
211+
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
212+
$ionicLoading.show({
213+
template: 'some other template'
214+
});
215+
$timeout.flush();
216+
expect(loader.element.text()).toBe('some other template');
217+
}));
192218

193219
});
220+

0 commit comments

Comments
 (0)