Returning data from angular $uibModal backdrop click

一世执手 提交于 2019-12-06 02:36:46

When you click on the backdrop outside, it does a dismiss internally.

Try using this inside modal:

$modalInstance.dismiss($scope.editMade);

And use this to handle data:

 instance.result.then(function(){
  //Get triggers when modal is closed
 }, function(){
  //gets triggers when modal is dismissed. You can basically handle data here
 });

Check this working plunker. It uses the dismiss as I mentioned

http://embed.plnkr.co/YdWmqYPFBNbv4vhQZc4t/

Passing custom data to your parent controller when modal is dismissed:

Code in Modal Controller:

  $scope.$on("modal.closing",function(){
       $rootScope.$broadcast("modalClosing",$scope.editMade);
  });

Then in your parent controller:

 $scope.$on("modalClosing",function(event,value){
    console.log(value); //value should be $scope.editMade
  });

You can learn more by reading the documentation here: https://github.com/angular-ui/bootstrap/tree/master/src/modal/docs

In the modal controller, you can do something like this:

$scope.$on('modal.closing', function(event, reason, closed) {
                if (reason == "backdrop click" || reason == "escape key press")
                {
                    event.preventDefault();
                    $uibModalInstance.close({"data": somedata});
                }                
            });

This way you'll always get the success callback on modalInstance

modalInstance.result.then(function(response) {
// here response will be whatever is passed. in this sample {"data": somedata}
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!