From 8e7fbf06a55c8dc507c8352d226e3b746bb8f3d0 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Sun, 8 Sep 2013 18:17:45 +0200 Subject: [PATCH] fix(modal): allow replacing object with default options Closes #967 --- src/modal/modal.js | 16 ++++++++-------- src/modal/test/modal.spec.js | 12 ++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/modal/modal.js b/src/modal/modal.js index 58a6870e9f..333b453e28 100644 --- a/src/modal/modal.js +++ b/src/modal/modal.js @@ -208,13 +208,11 @@ angular.module('ui.bootstrap.modal', []) .provider('$modal', function () { - var defaultOptions = { - backdrop: true, //can be also false or 'static' - keyboard: true - }; - - return { - options: defaultOptions, + var $modalProvider = { + options: { + backdrop: true, //can be also false or 'static' + keyboard: true + }, $get: ['$injector', '$rootScope', '$q', '$http', '$templateCache', '$controller', '$modalStack', function ($injector, $rootScope, $q, $http, $templateCache, $controller, $modalStack) { @@ -255,7 +253,7 @@ angular.module('ui.bootstrap.modal', []) }; //merge and clean up options - modalOptions = angular.extend({}, defaultOptions, modalOptions); + modalOptions = angular.extend({}, $modalProvider.options, modalOptions); modalOptions.resolve = modalOptions.resolve || {}; //verify options @@ -312,4 +310,6 @@ angular.module('ui.bootstrap.modal', []) return $modal; }] }; + + return $modalProvider; }); \ No newline at end of file diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index e1f3261c04..0bb734cfbc 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -202,6 +202,18 @@ describe('$modal', function () { expect($document).toHaveModalOpenWithContent('Content', 'div'); expect($document).not.toHaveBackdrop(); }); + + it('should accept new objects with default options in a provider', function () { + + $modalProvider.options = { + backdrop: false + }; + var modal = open({template: '
Content
'}); + + expect($document).toHaveModalOpenWithContent('Content', 'div'); + expect($document).not.toHaveBackdrop(); + }); + }); describe('option by option', function () {