Using $dialog to open a Controller and populate it with items

3,521 views
Skip to first unread message

Matt Raible

unread,
Mar 23, 2013, 4:25:21 AM3/23/13
to ang...@googlegroups.com
Hello,

I'm trying to use the following instructions to launch a Controller and associated dialog when I click on a link:


Here's the function in my main controller:

    $scope.configureDialog = function(type) {
        var dialog = $dialog.dialog({modalFade: false, resolve: {items: function(){ angular.copy($scope[type + 'Widgets'])} }});
        dialog.open('dialogs/dashboard-config.html', 'MyController');
    };

In controllers.js, MyController is defined as follows:

function MyController($scope, dialog, items) {
    $scope.items = items;
    $scope.submit = function(){
        dialog.close('ok');
    };
}

When I click the link to call configureDialog(), I get the following error:

Error: Unknown provider: dialogProvider <- dialog

If I change dialog to $dialog in MyController's constructor arguments, I get the following error:

Error: Unknown provider: itemsProvider <- items

Are the $dialog service's instructions wrong, or am I doing something wrong in my code?

Thanks,

Matt

johntom

unread,
Mar 23, 2013, 8:20:46 AM3/23/13
to ang...@googlegroups.com
Hi,
Here is a sample plunker I wrote a while back. Check to see what you are missing.
John

Matt Raible

unread,
Mar 23, 2013, 12:47:02 PM3/23/13
to ang...@googlegroups.com
Are you saying the best way to get data into a dialog is to put it in $rootScope (instead of a resolve variable)?

The following does work, just seems a lot different than the readme.

    $scope.configureDialog = function(type) {
        $rootScope.config = {};
        $rootScope.config.items = $scope[type + 'Widgets'];
        var dialog = $dialog.dialog({modalFade: false});
        dialog.open('dialogs/dashboard-config.html', 'MyController');
    };

function MyController($scope, $rootScope, dialog) {
    console.log($rootScope.config)
}

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/NUjPafxq9TI/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Pawel Kozlowski

unread,
Mar 23, 2013, 1:22:39 PM3/23/13
to ang...@googlegroups.com
Hi!

On Sat, Mar 23, 2013 at 5:47 PM, Matt Raible <mra...@gmail.com> wrote:
> Are you saying the best way to get data into a dialog is to put it in
> $rootScope (instead of a resolve variable)?

This is definitivelly _not_ the idea behind the $dialog service, we
should be not be polluting global scope. This is why the resolve part
exists.

@Matt, it is hard to say exactly what went wrong on your side without
a live plunk, but at least there was a missing return statement in the
resolve sections. Here is a working plunk that I've made based on your
code:

http://plnkr.co/edit/Z2mkIA?p=preview

Let me know if you see any potential improvements to the API so we
could make it easier on people.

Cheers,
Pawel


--
Looking for bootstrap-based widget library for AngularJS?
http://angular-ui.github.com/bootstrap/

Matt Raible

unread,
Mar 23, 2013, 2:38:34 PM3/23/13
to ang...@googlegroups.com
I think the missing return statement was the problem. Your plnkr helped me greatly and I got everything to work.

Thanks!

Matt

johntom

unread,
Mar 23, 2013, 5:14:19 PM3/23/13
to ang...@googlegroups.com
Sorry, I rushed my answer before traveling this am and found an old example and where I seem to remember having a problem with resolve.
Thanks Pawel for clarifying.
John
Reply all
Reply to author
Forward
0 new messages