Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I want have a table showing a list of students. When a user clicks on a one of these students, a modal form pops up showing the details of the student (this works fine). I expose the selected student to the modal control using resolve like below:

function showStudentDetails(){
        var modalInstance = $uibModal.open({
            templateUrl: 'tpl/student/app_student.view.html',
            controller: function($scope, $uibModalInstance, selectedStudent){
                $scope.selectedStudent = selectedStudent;
                $scope.userClickedCancel = function(){
                    $uibModalInstance.dismiss('cancel');
                }
                $scope.userClickedEdit = function(){
                    $uibModalInstance.close(selectedStudent);
                    modalInstance.result.then(function(selectedStudent){
                        showStudentEdit(selectedStudent);
                    })
                }
            },
            resolve: {
                selectedStudent: function() {
                    return $scope.selectedStudent;
                }
            }
        });
    }

Now, in this modal form there's an edit button which open a second modal.The second modal opens up fine and this is done by the

$scope.userClickedEdit = function(){
                $uibModalInstance.close(selectedStudent);
                modalInstance.result.then(function(selectedStudent){
                    showStudentEdit(selectedStudent);
                })
            }

in the first code snippet. The problem is the selectedStudent is not available in the context of my second modal form so the edit form input controls are blank. Below is my second modal form.

function showStudentEdit(selectedStudent){
        var modalInstance = $uibModal.open({
            templateUrl: 'tpl/student/app_student.edit.html',
            controller: function($scope, $uibModalInstance, selectedStudent){
                $scope.selectedStudent = selectedStudent;
                $scope.userClickedCancel = function(){
                    $uibModalInstance.dismiss('cancel');
                }
            },
            resolve: {
                selectedStudent: function(){
                    return selectedStudent;
                }
            }
        });
    }

Thanks for taking time to check this and appreciate any help.

share|improve this question
    
I don't see anything wrong. Could you write a plunkr reproducing the problem? I would move the modalInstance.result.then(...) to the bottom of the showStudentDetails()showStudentDetails() function, though. – JB Nizet 2 days ago
    
@JBNizet - Thanks for validation of the snippet. Just realised that I have been referencing the selectedStudent attribute by some other name in the view... Sorry to waste your time. – Sadeep 2 days ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.