提交表单后无法关闭模式弹出窗口

时间:2018-06-28 07:38:14

标签: angularjs

angular.module("simpleModalPop").controller("applicationListCtrl", [ "$scope", "masterService", "$rootScope", "Notification", "applicationService", "Constant", "$filter", "$state","$uibModal",
    function($scope, masterService, $rootScope, Notification, applicationService, Constant,$filter,$state, $uibModal) {
        console.log("applicationListCtrl....--->");
        $scope.modalInstanceObj = {};
        $scope.openModal = function(selected) {
            if($scope.currentObj.coApplicantUserId == 5){
                var modalInstance = $uibModal.open({
                    ariaLabelledBy : 'modal-title',
                    ariaDescribedBy : 'modal-body',
                    templateUrl : 'application/coApplicantProfile.html',
                    controller : 'profCtrl',
                    controllerAs : '$ctrl',
                    size : 'lg',
                    resolve : {
                    }
                });

                modalInstance.result.then(function(){
                    console.log("Modal is dimissed !");
                },
                function(res){
                    $scope.currentObj.coApplicantUserId={};
                });

                $scope.modalInstanceObj = modalInstance;
            }
        }

    } ]);

angular.module("simpleModalPop").controller("profCtrl", function($scope, userService) {

    $scope.initUserObj();
    $scope.createNewCoApplicant = function(){
        console.log("createNewCoApplicant");

        userService.creatCoApplicantProfile().then(
                function(success) {
                    $scope.isDisable = false;
                    if(success.data.status == 200){
                        $scope.modalInstanceObj.close('closed');
                    }else{
                        console.log(success.data.message);
                    }
                }, function(error) {
                    $scope.isDisable = false;                   
                    $scope.modalInstanceObj.close('closed');
         });        
    }

});

上面是我的js文件,在提交表单后尝试关闭模式弹出窗口。但这给我一个错误

  

“ TypeError:无法读取未定义的属性'close'”

我已经将['ui.bootstrap']注入了另一个js文件。我正在使用angularjs V 1.7.x

3 个答案:

答案 0 :(得分:0)

这些类型的行中存在错误

$scope.modalInstanceObj.close

由于未定义$ scope.modalInstanceObj。

答案 1 :(得分:0)

当您试图从另一个“ profCtrl”控制器的作用域访问“ $ scope.modalInstanceObj”时,您已在“ applicationListCtrl”控制器中定义了“ $ scope.modalInstanceObj”。如果两个模板/控制器是同级,请尝试使用事件,或者尝试使用父/子属性进行访问。

答案 2 :(得分:0)

尝试一下...

$uibModalInstance注入控制器profCtrl

$scope.modalInstanceObj.close('closed');替换为$uibModalInstance.close('closed');

angular.module("simpleModalPop").controller("profCtrl", function($scope,$uibModalInstance,userService) {

    $scope.initUserObj();
    $scope.createNewCoApplicant = function(){
        console.log("createNewCoApplicant");

        userService.creatCoApplicantProfile().then(
                function(success) {
                    $scope.isDisable = false;
                    if(success.data.status == 200){
                      $uibModalInstance.close('closed'); //replaced  $scope.modalInstanceObj.close('closed');
                    }else{
                        console.log(success.data.message);
                    }
                }, function(error) {
                    $scope.isDisable = false;                   
                    $uibModalInstance.close('closed');
         });        
    }

});