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

javascript - Angular ui bootstrap modal passing multiple parameters - Stack Overflow

programmeradmin1浏览0评论

I am using an angular ui bootstrap modal for one of my applications. Currently i am calling the modal instance using the following:

<button class="btn btn-default btn-sm pull-right" 
ng-click="open({{node.id}})">Add Course <span class="glyphicon glyphicon-plus">
</span>
</button>

I have defined the modal as follows:

$scope.open = function (node) {
    var modalInstance = $modal.open({
        templateUrl: 'myModalContent.html',
        controller: ModalInstanceCtrl,
        resolve: {
            detail: function() {
                return node;
            }
        }   
    });
};

Here the open() function passes the id of the node. Here node is a django item which has details like id, required etc..

My modal instance is defined as follows:

var ModalInstanceCtrl = function ($scope, $http, $log, $modalInstance, detail) {
    $scope.subcategory = detail;
};

So far the modal works fine and i am able to pass the node.id to the modal. But now i want to pass even the other parameters within the node like open({{node.required}}, {{node.id}}) etc to the modal. How do i modify my modal open() and modalinstance() functions to receive multiplt parameters?

I am using an angular ui bootstrap modal for one of my applications. Currently i am calling the modal instance using the following:

<button class="btn btn-default btn-sm pull-right" 
ng-click="open({{node.id}})">Add Course <span class="glyphicon glyphicon-plus">
</span>
</button>

I have defined the modal as follows:

$scope.open = function (node) {
    var modalInstance = $modal.open({
        templateUrl: 'myModalContent.html',
        controller: ModalInstanceCtrl,
        resolve: {
            detail: function() {
                return node;
            }
        }   
    });
};

Here the open() function passes the id of the node. Here node is a django item which has details like id, required etc..

My modal instance is defined as follows:

var ModalInstanceCtrl = function ($scope, $http, $log, $modalInstance, detail) {
    $scope.subcategory = detail;
};

So far the modal works fine and i am able to pass the node.id to the modal. But now i want to pass even the other parameters within the node like open({{node.required}}, {{node.id}}) etc to the modal. How do i modify my modal open() and modalinstance() functions to receive multiplt parameters?

Share Improve this question asked May 20, 2014 at 16:47 AbhishekAbhishek 3,0689 gold badges46 silver badges94 bronze badges 4
  • 2 It looks like you should just replace open({{node.id}}) with open(node) in your ng-click this way you can pass the whole node into your ModalInstanceCtrl. However if you wanted to add more constructor parameters to be injected when an instance of ModalInstanceCtrl is created, you would have to add them to the resolve object. – Mark At Ramp51 Commented May 20, 2014 at 17:12
  • i tried doing both. But they were not working for some reason – Abhishek Commented May 20, 2014 at 17:13
  • Post a plunker if you need help, it is very hard to assist based on the provided description. – pkozlowski.opensource Commented May 20, 2014 at 17:14
  • Can you show the code that you were trying to write that wasn't working? – Mark At Ramp51 Commented May 20, 2014 at 17:14
Add a comment  | 

1 Answer 1

Reset to default 20

You can add more objects to the resolve section:

$scope.open = function (node, node2) {
    var modalInstance = $modal.open({
        templateUrl: 'myModalContent.html',
        controller: ModalInstanceCtrl,
        resolve: {
            detail: function() {
                return node;
            },
            detail2: function() {
                return node2;
            }
        }   
    });
};
发布评论

评论列表(0)

  1. 暂无评论