0

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?

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

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.

Community
  • 1
  • 1
user1935987
  • 3,136
  • 9
  • 56
  • 108

1 Answers1

0

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

//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
})
Maverick
  • 454
  • 2
  • 11
  • sorry, i dont really understood. so, i need to pass a whole $scope inmodal controller and here `$scope.$on('modal.hide', function(event, reason, closed){ //use the data from the factory/service(set in the modal) here. }` capture the needed value? – user1935987 May 20 '16 at 10:46
  • Did you tested smth like that? done that, but no errors, just nothing happened. `$scope.$on('modal.hide'` in modal's controller is not fired – user1935987 May 23 '16 at 06:54
  • I have created a plnkr. Sorry the event name was wrong up there. Corrected the code also http://plnkr.co/edit/zHnFmR2SPJ4BFvGU0XL4 – Maverick May 23 '16 at 08:53
  • just tried to put this in modal's controller `$scope.$on('modal.hide', function(event, reason, closed){ console.log("modal hide fired"); $scope.$on("modal.closing",function(){ console.log("modal closing fired"); $rootScope.$broadcast("modalClosing",$scope.choosenLocationLatLng); }); });` nothing logging on background click modal closing or ESC keyboard closing. – user1935987 May 23 '16 at 14:37
  • can you create a plnkr? or check the plnkr I gave .. its working fine and logging the value – Maverick May 24 '16 at 08:32