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

javascript - returning uibmodal result to parent controller - Stack Overflow

programmeradmin0浏览0评论

so here is my modal JS:

function modalInstance() {
        var ctrlr = function($scope,$uibModalInstance,inName) {
            var init = function() {
                $scope.modalTmpStep = {
                    pos: 0,
                    body: ''
                };
                $scope.cancelStep = cancelStep;
                $scope.submitStep = saveStep;
            };

            function cancelStep() {
                console.log('closing');
                $uibModalInstance.dismiss('dismissed');
            }
            function saveStep() {
                var submitVar = JSON.stringify($scope.modalTmpStep)
                console.log('submitting')
                $uibModalInstance.close(submitVar);
            }

            init()
        };

        var modalInstance = $uibModal.open({
            animation: true,
            templateUrl: 'main/add/stepModal/addModal.html',
            controller: ctrlr,
            size: 'lg',
            backdrop: 'static'
        });

        modalInstance.result.then(function() {
            console.log();
        })

    }

so here is my modal JS:

function modalInstance() {
        var ctrlr = function($scope,$uibModalInstance,inName) {
            var init = function() {
                $scope.modalTmpStep = {
                    pos: 0,
                    body: ''
                };
                $scope.cancelStep = cancelStep;
                $scope.submitStep = saveStep;
            };

            function cancelStep() {
                console.log('closing');
                $uibModalInstance.dismiss('dismissed');
            }
            function saveStep() {
                var submitVar = JSON.stringify($scope.modalTmpStep)
                console.log('submitting')
                $uibModalInstance.close(submitVar);
            }

            init()
        };

        var modalInstance = $uibModal.open({
            animation: true,
            templateUrl: 'main/add/stepModal/addModal.html',
            controller: ctrlr,
            size: 'lg',
            backdrop: 'static'
        });

        modalInstance.result.then(function() {
            console.log();
        })

    }

The end goal of this piece of code is to print the object "submitVar" somewhere on the parent page, the object could be a string or a JSON. All the variables in questions are being chaned using ng-model in the HTML. I don't know how to pass this value back to the parent controller and need some help.

Currently the line console.log('submitting') runs, but i don't know where the submitVar result is placed. I'm planning to use this as as an editing window, so an object is passed in, then edited and passed back, changing the current value.

I'm using: https://angular-ui.github.io/bootstrap/ as a reference and cant find any other documentation on this.

Share Improve this question asked Dec 7, 2016 at 21:33 TobyStackTobyStack 3211 gold badge4 silver badges16 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 15

Inside result.then of modalInstance object you can get value returned while closing modalInstance

modalInstance.result.then(function(submitVar) {
    console.log("sumbited value inside parent controller", submitVar);
})
发布评论

评论列表(0)

  1. 暂无评论