1
votes

How can I open a modal inside of a modal? Ive followed this plnkr but I got an error when I click the confirm button of the second modal. This is the error:

Error: [$injector:unpr]

This is my first modal

$scope.edit = function(data) {
        var modalInstance = $uibModal.open({
            templateUrl: "/wp-content/themes/copywriter-theme/angular-modal-template/management_modal.html",
            controller: 'managementModal',
            resolve: {
                items: function() {
                    return data;
                }
            }
        });
}

This is my 2nd modal

angular.module(['ui.bootstrap']).controller('managementModal',['$scope','$http','$uibModalInstance','$uibModal','items',function($scope, $http, $uibModalInstance, $uibModal, items){
    $scope.names = items;
    $scope.editable = items;

    $scope.cancel = function(){
        $uibModalInstance.dismiss('cancel');
        location.reload();
    };

    $scope.confirm = function(){
        console.log("clicked");
        $uibModalInstance.close($scope.editable);
    }

    $scope.update = function(){
        var template_modal = "<div class='modal-body'>" +
                                "<button type='button' class='close' ng-click='confirm()'>update</button>" +
                                "<button type='button' class='close' ng-click='cancel()'>cancel</button>" +
                            "</div>";
        var modalInstance = $uibModal.open({
            template: template_modal,
            controller: 'managementModal'
        });
    };
}]);

So the first modal is in another controller while the second modal is inside of the controller managementModal. But in plnkr its okay to click the button and its working I dont know why my button on my second modal are not working

1
Does it work on your development env or you tested after minify it - Maxim Shoustin
Further, if it works in Plunker - we cannot help you. look for problem in your project - Maxim Shoustin
@MaximShoustin nope its not working in my development - Pure Rhymer Organization

1 Answers

0
votes

I got it the answer is I need to re declare again the items so in my second modal this should be the code

$scope.update = function(){
        var template_modal = "<div class='modal-body'>" +
                                "<button type='button' class='close' ng-click='confirm()'>update</button>" +
                                "<button type='button' class='close' ng-click='cancel()'>cancel</button>" +
                            "</div>";
        var modalInstance = $uibModal.open({
            template: template_modal,
            controller: 'managementModal',
            //added code
            resolve: {
                items: function() {
                    return items;
                }
            }
        });
    };