Skip to content

Commit

Permalink
feat(modal): allow users to resolve with strings
Browse files Browse the repository at this point in the history
- Allows users to specify a string reference to a service for injection

Closes angular-ui#2676
  • Loading branch information
wesleycho committed Aug 6, 2015
1 parent c7f19d5 commit 30aa6e5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/modal/modal.js
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
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

0 comments on commit 30aa6e5

Please sign in to comment.