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

Commit

Permalink
feat(modal): allow templateUrl to be a function
Browse files Browse the repository at this point in the history
Fixes #2296
  • Loading branch information
pkozlowski-opensource committed Jun 5, 2014
1 parent 6e83dc6 commit 990015f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}

Expand Down
19 changes: 18 additions & 1 deletion src/modal/test/modal.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe('$modal', function () {
ddescribe('$modal', function () {
var $controllerProvider, $rootScope, $document, $compile, $templateCache, $timeout, $q;
var $modal, $modalProvider;

Expand Down Expand Up @@ -280,6 +280,23 @@ describe('$modal', function () {
expect($document).toHaveModalOpenWithContent('Whitespaces', 'div');
});

it('should accept template as a function', function () {
open({template: function() {
return '<div>From a function</div>';
}});

expect($document).toHaveModalOpenWithContent('From a function', 'div');
});

it('should not fail if a templateUrl as a function', function () {

$templateCache.put('whitespace.html', ' <div>Whitespaces</div> ');
open({templateUrl: function(){
return 'whitespace.html';
}});
expect($document).toHaveModalOpenWithContent('Whitespaces', 'div');
});

});

describe('controller', function () {
Expand Down

0 comments on commit 990015f

Please sign in to comment.