Skip to content

Commit 30aa6e5

Browse files
committed
feat(modal): allow users to resolve with strings
- Allows users to specify a string reference to a service for injection Closes angular-ui#2676
1 parent c7f19d5 commit 30aa6e5

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Diff for: src/modal/modal.js

+2
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,8 @@ angular.module('ui.bootstrap.modal', [])
540540
angular.forEach(resolves, function (value) {
541541
if (angular.isFunction(value) || angular.isArray(value)) {
542542
promisesArr.push($q.when($injector.invoke(value)));
543+
} else if (angular.isString(value)) {
544+
promisesArr.push($q.when($injector.get(value)));
543545
}
544546
});
545547
return promisesArr;

Diff for: src/modal/test/modal.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,21 @@ describe('$modal', function () {
523523
expect($document).toHaveModalOpenWithContent('Content from resolve', 'div');
524524
});
525525

526+
it('should resolve string references to injectables', function () {
527+
open({
528+
controller: function($scope, $foo) {
529+
$scope.value = 'Content from resolve';
530+
expect($foo).toBe($modal);
531+
},
532+
resolve: {
533+
$foo: '$modal'
534+
},
535+
template: '<div>{{value}}</div>'
536+
});
537+
538+
expect($document).toHaveModalOpenWithContent('Content from resolve', 'div');
539+
});
540+
526541
it('should delay showing modal if one of the resolves is a promise', function () {
527542

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

0 commit comments

Comments
 (0)