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

Commit

Permalink
feat(dialog): Make $dialog 'resolve' property to work the same way of…
Browse files Browse the repository at this point in the history
… $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>
  • Loading branch information
thiagofelix authored and ajoslin committed Feb 6, 2013
1 parent a790b94 commit 739f86f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/dialog/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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);
Expand Down Expand Up @@ -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.');
}
Expand Down Expand Up @@ -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');
Expand Down
11 changes: 8 additions & 3 deletions src/dialog/test/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('Given ui.bootstrap.dialog', function(){
});
});

/*
/*
describe('modalFade:true, backdropFade:true', function(){
useDialogWithGlobalOption({modalFade:true, backdropFade:true});
Expand Down Expand Up @@ -167,15 +167,20 @@ 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;
}

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();
});
Expand Down

1 comment on commit 739f86f

@pkozlowski-opensource
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduced #126

Please sign in to comment.