diff --git a/config/docs/templates/api_menu_version.template.html b/config/docs/templates/api_menu_version.template.html
index cd54afe6c5..b4adc1b468 100644
--- a/config/docs/templates/api_menu_version.template.html
+++ b/config/docs/templates/api_menu_version.template.html
@@ -360,6 +360,13 @@
+
diff --git a/js/angular/service/loading.js b/js/angular/service/loading.js
index a1ca83f5a9..354be3723e 100644
--- a/js/angular/service/loading.js
+++ b/js/angular/service/loading.js
@@ -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: ''
+})
.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
diff --git a/test/unit/angular/service/loading.unit.js b/test/unit/angular/service/loading.unit.js
index b5ef3b6109..36f0a9cf69 100644
--- a/test/unit/angular/service/loading.unit.js
+++ b/test/unit/angular/service/loading.unit.js
@@ -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');
+ }));
});
+