From 739f86f21a2919654bcb01f3edc6ddeeb1b35c22 Mon Sep 17 00:00:00 2001 From: thiagofelix Date: Mon, 4 Feb 2013 17:10:42 -0200 Subject: [PATCH] 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 --- src/dialog/dialog.js | 12 ++++++------ src/dialog/test/dialog.js | 11 ++++++++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/dialog/dialog.js b/src/dialog/dialog.js index fb7bd17e83..34efd72831 100644 --- a/src/dialog/dialog.js +++ b/src/dialog/dialog.js @@ -41,8 +41,8 @@ dialogModule.provider("$dialog", function(){ }; // Returns the actual `$dialog` service that is injected in controllers - this.$get = ["$http", "$document", "$compile", "$rootScope", "$controller", "$templateCache", "$q", "$transition", - function ($http, $document, $compile, $rootScope, $controller, $templateCache, $q, $transition) { + this.$get = ["$http", "$document", "$compile", "$rootScope", "$controller", "$templateCache", "$q", "$transition", "$injector", + function ($http, $document, $compile, $rootScope, $controller, $templateCache, $q, $transition, $injector) { var body = $document.find('body'); @@ -54,9 +54,9 @@ dialogModule.provider("$dialog", function(){ // The `Dialog` class represents a modal dialog. The dialog class can be invoked by providing an options object // containing at lest template or templateUrl and controller: - // + // // var d = new Dialog({templateUrl: 'foo.html', controller: 'BarController'}); - // + // // Dialogs can also be created using templateUrl and controller as distinct arguments: // // var d = new Dialog('path/to/dialog.html', MyDialogController); @@ -107,7 +107,7 @@ dialogModule.provider("$dialog", function(){ if(controller){ options.controller = controller; } - + if(!(options.template || options.templateUrl)) { throw new Error('Dialog.open expected template or templateUrl, neither found. Use options or open method to specify them.'); } @@ -217,7 +217,7 @@ dialogModule.provider("$dialog", function(){ angular.forEach(this.options.resolve || [], function(value, key) { keys.push(key); - values.push(value); + values.push(angular.isString(value) ? $injector.get(value) : $injector.invoke(value)); }); keys.push('$template'); diff --git a/src/dialog/test/dialog.js b/src/dialog/test/dialog.js index f6d8493bc7..098baa9996 100644 --- a/src/dialog/test/dialog.js +++ b/src/dialog/test/dialog.js @@ -122,7 +122,7 @@ describe('Given ui.bootstrap.dialog', function(){ }); }); - /* + /* describe('modalFade:true, backdropFade:true', function(){ useDialogWithGlobalOption({modalFade:true, backdropFade:true}); @@ -167,7 +167,7 @@ describe('Given ui.bootstrap.dialog', function(){ describe('When opening a dialog with resolves', function(){ - var resolvedFoo, resolvedBar, deferred; + var resolvedFoo, resolvedBar, deferred, resolveObj; function Ctrl(foo, bar){ resolvedFoo = foo; resolvedBar = bar; @@ -175,7 +175,12 @@ describe('Given ui.bootstrap.dialog', function(){ beforeEach(function(){ deferred = q.defer(); - createDialog({template:template, resolve: {foo: 'foo', bar: deferred.promise}, controller: Ctrl}); + resolveObj = { + foo: function(){return 'foo';}, + bar: function(){return deferred.promise;} + }; + + createDialog({template:template, resolve: resolveObj, controller: Ctrl}); deferred.resolve('bar'); openDialog(); });