Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameters to modal dialog

I'm trying to use a simple modal dialog for editing an item in a list in the context of an Angular app. For modals I'm using UI-Bootstrap (AngularUI), which I know has still issues with Bootstrap 3 but AFAIK can be used for modals with some simple workarounds (unless building the not-yet-released branch of AngularUI). I created a simple repro Plunker here:

http://plnkr.co/edit/MWa3bLMqIkwxmxQ6YDSl

The sample code has a couple of controllers, one with an open method which should open the modal, and another with save and close methods for buttons save and cancel. Also, the CSS contains some workarounds for dealing with AngularUI issues with Bootstrap 3. The modal dialog is displayed, but it does not receive the parameter passed from the calling controller. To pass this parameter (a dummy item object with an id and a name) I use the resolve option in the modal open method call, like:

resolve: {
  item: function() {
    return angular.copy(item);
  }
}

Yet, the item parameter which should be resolved in the dialog controller appears to be undefined. What I'm missing here? Thanks!

like image 433
Naftis Avatar asked Dec 12 '13 14:12

Naftis


1 Answers

You need to inject the item in controller injection:

You have this:

ItemDialogController.$inject = ["$scope", "$modalInstance"];

Change to:

 ItemDialogController.$inject = ["$scope", "$modalInstance", "item"];
like image 197
Deividi Cavarzan Avatar answered Nov 08 '22 10:11

Deividi Cavarzan