Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularjs $modal close modal

Im trying to make an angularjs Modal service. I have an controller that opens some modal, in that modal i call original controller functions or access some variables, this part i can make it already. I just cant close modal without clicking cancel or ok buttons, o want to make some operations in the modal, call some werbservices and the close modal manually. Can anyone help me?

I made an working plunker here: plunker

var modalInstance = $modal.open({
              templateUrl: 'myModalContent2.html',
              controller: ModalInstanceCtrl,
              size: size,
              scope: $scope

            });
like image 563
John Avatar asked Sep 16 '14 14:09

John


People also ask

How to close modal AngularJS?

To close a $modal that you have opened you can follow these steps. 1) Inject $modalInstance into the controller that you specified when you created the modal. In your case you called it ModalInstanceCtrl . 2) Have a function in your ModalInstanceCtrl that calls .

What is $Uibmodal in AngularJS?

$uibmodal is a service to create modal windows. Uibmodal is the UI Bootstrap component written in AngularJS. It enables us to use Bootstrap in AngularJS. It provides directives for all bootstrap with some extra like, datepicker, timepicker etc.


1 Answers

To close a $modal that you have opened you can follow these steps.

1) Inject $modalInstance into the controller that you specified when you created the modal. In your case you called it ModalInstanceCtrl.

2) Have a function in your ModalInstanceCtrl that calls .close() on $modalInstance.

your ModalInstanceCtrl should look something like this

angular.module('myCoolApp')
  .controller('ModalInstanceCtrl', function ($scope, $modalInstance) {

    $scope.closeModal = function(){
       $modalInstance.close();
    }

});
like image 61
Benjamin Conant Avatar answered Oct 14 '22 04:10

Benjamin Conant