angularjs $modal close modal

冷暖自知 提交于 2021-02-07 12:35:28

问题


Im trying to make an angularjs Modal service. I have an controller that opens some modal, in that modal i call original controller functions or access some variables, this part i can make it already. I just cant close modal without clicking cancel or ok buttons, o want to make some operations in the modal, call some werbservices and the close modal manually. Can anyone help me?

I made an working plunker here: plunker

var modalInstance = $modal.open({
              templateUrl: 'myModalContent2.html',
              controller: ModalInstanceCtrl,
              size: size,
              scope: $scope

            });

回答1:


To close a $modal that you have opened you can follow these steps.

1) Inject $modalInstance into the controller that you specified when you created the modal. In your case you called it ModalInstanceCtrl.

2) Have a function in your ModalInstanceCtrl that calls .close() on $modalInstance.

your ModalInstanceCtrl should look something like this

angular.module('myCoolApp')
  .controller('ModalInstanceCtrl', function ($scope, $modalInstance) {

    $scope.closeModal = function(){
       $modalInstance.close();
    }

});



回答2:


$scope.myData='all data can be';
$scope.myModalInstance = $modal.open({
    templateUrl: 'app/myOpen.html',
    controller: 'myOpenController',
    size: 'lg', //modal open size large
    backdrop: 'static',
    keyboard: false,
    resolve: {
        myData: function () {
            return $scope.myData;
            }
        }
    });
$scope.modalClose = function (){
   $scope.myModalInstance.close();
}


来源:https://stackoverflow.com/questions/25871247/angularjs-modal-close-modal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!