diff --git a/src/modal/modal.js b/src/modal/modal.js index 1435087f11..317f36737d 100644 --- a/src/modal/modal.js +++ b/src/modal/modal.js @@ -303,8 +303,9 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition']) function getTemplatePromise(options) { return options.template ? $q.when(options.template) : - $http.get(options.templateUrl, {cache: $templateCache}).then(function (result) { - return result.data; + $http.get(angular.isFunction(options.templateUrl) ? (options.templateUrl)() : options.templateUrl, + {cache: $templateCache}).then(function (result) { + return result.data; }); } diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index d556b21f19..9c3738d013 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -1,4 +1,4 @@ -describe('$modal', function () { +ddescribe('$modal', function () { var $controllerProvider, $rootScope, $document, $compile, $templateCache, $timeout, $q; var $modal, $modalProvider; @@ -280,6 +280,23 @@ describe('$modal', function () { expect($document).toHaveModalOpenWithContent('Whitespaces', 'div'); }); + it('should accept template as a function', function () { + open({template: function() { + return '
From a function
'; + }}); + + expect($document).toHaveModalOpenWithContent('From a function', 'div'); + }); + + it('should not fail if a templateUrl as a function', function () { + + $templateCache.put('whitespace.html', '
Whitespaces
'); + open({templateUrl: function(){ + return 'whitespace.html'; + }}); + expect($document).toHaveModalOpenWithContent('Whitespaces', 'div'); + }); + }); describe('controller', function () {