如何在关闭angularjs指令的bootstrap模式之前触发事件

时间:2015-11-10 09:26:28

标签: javascript jquery angularjs twitter-bootstrap

如何在关闭angularjs指令上的bootstrap模式之前触发事件,

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

模板

< DIV>我的模态< / DIV>

和指令

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');
     });
    }
});

我希望在点击背景后关闭模式之前确认消息。 从这里调用模态对话框

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

            });
  }

1 个答案:

答案 0 :(得分:0)

查看this答案,这对我有用。

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

 instance.result.then(function(){
  //Get triggers when modal is closed
 }, function(){
  //gets triggers when modal is dismissed.
 });