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

feat(modal): allow users to resolve with strings #4124

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,8 @@ angular.module('ui.bootstrap.modal', [])
angular.forEach(resolves, function (value) {
if (angular.isFunction(value) || angular.isArray(value)) {
promisesArr.push($q.when($injector.invoke(value)));
} else if (angular.isString(value)) {
promisesArr.push($q.when($injector.get(value)));
}
});
return promisesArr;
Expand Down
15 changes: 15 additions & 0 deletions src/modal/test/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,21 @@ describe('$modal', function () {
expect($document).toHaveModalOpenWithContent('Content from resolve', 'div');
});

it('should resolve string references to injectables', function () {
open({
controller: function($scope, $foo) {
$scope.value = 'Content from resolve';
expect($foo).toBe($modal);
},
resolve: {
$foo: '$modal'
},
template: '<div>{{value}}</div>'
});

expect($document).toHaveModalOpenWithContent('Content from resolve', 'div');
});

it('should delay showing modal if one of the resolves is a promise', function () {

open(modalDefinition('<div>{{value}}</div>', {
Expand Down