Angular UI Bootstrap Modal在背景点击/ ESC键盘关闭时将数据传回父控制器

时间:2022-06-02 11:29:08

everyone.

Will start from the prob - How can i pass the variable back from the AngularJS UI Boostrap Modal on the user's background click or ESC button keyboard trigger?

将从问题开始 - 如何在用户的背景单击或ESC按钮键盘触发器上从AngularJS UI Boostrap Modal传回变量?

there are solution to prevent user for doing that: How do I prevent angular-ui modal from closing?

有防止用户这样做的解决方案:如何防止angular-ui模态关闭?

But in my case, i think it can make a user stuck, because there is only one btn triggering the $uibModalInstance.close($scope.choosenLocationLatLng); action. So i want to pass the variable back on background click and ESC keyboard btn also if its possible.

但在我的情况下,我认为它可以让用户卡住,因为只有一个btn触发$ uibModalInstance.close($ scope.choosenLocationLatLng);行动。所以我想在背景点击和ESC键盘btn上传回变量,如果可能的话。

1 个解决方案

#1


0  

The closing event of $uibModal can be trapped and used to communicate with parent controller.

$ uibModal的关闭事件可以被捕获并用于与父控制器通信。

//main controller
var modalInstance = $uibModal.open({
  templateUrl: 'a-template.html',
  controller: ['$scope','$rootScope', function($scope, $){
    //This goes in modal ctrl
    //----------------------------------------------------------
    $scope.$on('modal.hide', function(event, reason, closed){
           $scope.$on("modal.closing",function(){
           $rootScope.$broadcast("modalClosing",$scope.latLong);
     });
    }
    //---------------------------------------------------------
  }],
  controllerAs: 'modal',
  size: 'lg'
});
$scope.$on('modalClosing',function(value){
  //value is the latlong set in modal
})

#1


0  

The closing event of $uibModal can be trapped and used to communicate with parent controller.

$ uibModal的关闭事件可以被捕获并用于与父控制器通信。

//main controller
var modalInstance = $uibModal.open({
  templateUrl: 'a-template.html',
  controller: ['$scope','$rootScope', function($scope, $){
    //This goes in modal ctrl
    //----------------------------------------------------------
    $scope.$on('modal.hide', function(event, reason, closed){
           $scope.$on("modal.closing",function(){
           $rootScope.$broadcast("modalClosing",$scope.latLong);
     });
    }
    //---------------------------------------------------------
  }],
  controllerAs: 'modal',
  size: 'lg'
});
$scope.$on('modalClosing',function(value){
  //value is the latlong set in modal
})