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

Commit 739f86f

Browse files
thiagofelixajoslin
authored andcommitted
feat(dialog): Make $dialog 'resolve' property to work the same way of $routeProvider.when
Changing the $dialog service to treat the 'resolve' property the same way as $routeProvider does. It means expecting a string or a factory function instead of a value. Signed-off-by: thiagofelix <felixthi@gmail.com>
1 parent a790b94 commit 739f86f

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/dialog/dialog.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ dialogModule.provider("$dialog", function(){
4141
};
4242

4343
// Returns the actual `$dialog` service that is injected in controllers
44-
this.$get = ["$http", "$document", "$compile", "$rootScope", "$controller", "$templateCache", "$q", "$transition",
45-
function ($http, $document, $compile, $rootScope, $controller, $templateCache, $q, $transition) {
44+
this.$get = ["$http", "$document", "$compile", "$rootScope", "$controller", "$templateCache", "$q", "$transition", "$injector",
45+
function ($http, $document, $compile, $rootScope, $controller, $templateCache, $q, $transition, $injector) {
4646

4747
var body = $document.find('body');
4848

@@ -54,9 +54,9 @@ dialogModule.provider("$dialog", function(){
5454

5555
// The `Dialog` class represents a modal dialog. The dialog class can be invoked by providing an options object
5656
// containing at lest template or templateUrl and controller:
57-
//
57+
//
5858
// var d = new Dialog({templateUrl: 'foo.html', controller: 'BarController'});
59-
//
59+
//
6060
// Dialogs can also be created using templateUrl and controller as distinct arguments:
6161
//
6262
// var d = new Dialog('path/to/dialog.html', MyDialogController);
@@ -107,7 +107,7 @@ dialogModule.provider("$dialog", function(){
107107
if(controller){
108108
options.controller = controller;
109109
}
110-
110+
111111
if(!(options.template || options.templateUrl)) {
112112
throw new Error('Dialog.open expected template or templateUrl, neither found. Use options or open method to specify them.');
113113
}
@@ -217,7 +217,7 @@ dialogModule.provider("$dialog", function(){
217217

218218
angular.forEach(this.options.resolve || [], function(value, key) {
219219
keys.push(key);
220-
values.push(value);
220+
values.push(angular.isString(value) ? $injector.get(value) : $injector.invoke(value));
221221
});
222222

223223
keys.push('$template');

src/dialog/test/dialog.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ describe('Given ui.bootstrap.dialog', function(){
122122
});
123123
});
124124

125-
/*
125+
/*
126126
describe('modalFade:true, backdropFade:true', function(){
127127
useDialogWithGlobalOption({modalFade:true, backdropFade:true});
128128
@@ -167,15 +167,20 @@ describe('Given ui.bootstrap.dialog', function(){
167167

168168
describe('When opening a dialog with resolves', function(){
169169

170-
var resolvedFoo, resolvedBar, deferred;
170+
var resolvedFoo, resolvedBar, deferred, resolveObj;
171171
function Ctrl(foo, bar){
172172
resolvedFoo = foo;
173173
resolvedBar = bar;
174174
}
175175

176176
beforeEach(function(){
177177
deferred = q.defer();
178-
createDialog({template:template, resolve: {foo: 'foo', bar: deferred.promise}, controller: Ctrl});
178+
resolveObj = {
179+
foo: function(){return 'foo';},
180+
bar: function(){return deferred.promise;}
181+
};
182+
183+
createDialog({template:template, resolve: resolveObj, controller: Ctrl});
179184
deferred.resolve('bar');
180185
openDialog();
181186
});

0 commit comments

Comments
 (0)