Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 990015f

Browse files
feat(modal): allow templateUrl to be a function
Fixes #2296
1 parent 6e83dc6 commit 990015f

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/modal/modal.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,9 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition'])
303303

304304
function getTemplatePromise(options) {
305305
return options.template ? $q.when(options.template) :
306-
$http.get(options.templateUrl, {cache: $templateCache}).then(function (result) {
307-
return result.data;
306+
$http.get(angular.isFunction(options.templateUrl) ? (options.templateUrl)() : options.templateUrl,
307+
{cache: $templateCache}).then(function (result) {
308+
return result.data;
308309
});
309310
}
310311

src/modal/test/modal.spec.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe('$modal', function () {
1+
ddescribe('$modal', function () {
22
var $controllerProvider, $rootScope, $document, $compile, $templateCache, $timeout, $q;
33
var $modal, $modalProvider;
44

@@ -280,6 +280,23 @@ describe('$modal', function () {
280280
expect($document).toHaveModalOpenWithContent('Whitespaces', 'div');
281281
});
282282

283+
it('should accept template as a function', function () {
284+
open({template: function() {
285+
return '<div>From a function</div>';
286+
}});
287+
288+
expect($document).toHaveModalOpenWithContent('From a function', 'div');
289+
});
290+
291+
it('should not fail if a templateUrl as a function', function () {
292+
293+
$templateCache.put('whitespace.html', ' <div>Whitespaces</div> ');
294+
open({templateUrl: function(){
295+
return 'whitespace.html';
296+
}});
297+
expect($document).toHaveModalOpenWithContent('Whitespaces', 'div');
298+
});
299+
283300
});
284301

285302
describe('controller', function () {

0 commit comments

Comments
 (0)