From 30aa6e55e61a749d843ceeac6eaac8b4fe9ff13b Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Thu, 6 Aug 2015 00:55:43 -0700 Subject: [PATCH] feat(modal): allow users to resolve with strings - Allows users to specify a string reference to a service for injection Closes #2676 --- src/modal/modal.js | 2 ++ src/modal/test/modal.spec.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/modal/modal.js b/src/modal/modal.js index 0e66f8c7c8..2142aeb21e 100644 --- a/src/modal/modal.js +++ b/src/modal/modal.js @@ -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; diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index e79062ae9f..1da3485ecc 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -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: '
{{value}}
' + }); + + expect($document).toHaveModalOpenWithContent('Content from resolve', 'div'); + }); + it('should delay showing modal if one of the resolves is a promise', function () { open(modalDefinition('
{{value}}
', {