0

How to trigger event before closing bootstrap modal on angularjs directive ,

angular.module('app').controller("myModal", function myModal($scope, $modalInstance) {
$scope.modalInstance = $modalInstance;
});

template

< div> My modal < /div>

and directive

angular.module('app').directive('mymodal',function( $rootScope ){
return{
    restrict : 'E',
    replace : true,
    templateUrl :'mymodal.html',
    scope :{
        modalInstance :'='
    },
    link: function (scope, elem, attr) {
     scope.modalInstance.result.then(function() {
        console.log('close');
     }, function() {
       console.log('dimiss');
     });
    }
});

I want to have confirm message before closing modal after click on backdrop. call modal dialog from here

      $scope.openModal = function() {
      $scope.modalInstance = $modal.open({
                animation: true,
                template: '<mymodal modal-instance="modalInstance"></mymodal>',
                controller: 'myModal',
                backdrop: true,
                keyboard: true,

            });
  }
Sophon Men
  • 179
  • 1
  • 2
  • 10

1 Answers1

0

Check out this answer, it works for me.

var instance = $modal.open(...);

 instance.result.then(function(){
  //Get triggers when modal is closed
 }, function(){
  //gets triggers when modal is dismissed.
 });
Community
  • 1
  • 1
kalifa17
  • 137
  • 7