最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Passing parameters to modal dialog - Stack Overflow

programmeradmin7浏览0评论

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:

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!

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!

Share Improve this question edited Dec 1, 2014 at 17:32 isherwood 61.2k16 gold badges121 silver badges170 bronze badges asked Dec 12, 2013 at 14:53 NaftisNaftis 4,5597 gold badges69 silver badges96 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

You need to inject the item in controller injection:

You have this:

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

Change to:

 ItemDialogController.$inject = ["$scope", "$modalInstance", "item"];
发布评论

评论列表(0)

  1. 暂无评论