Angularjs $ modal close modal

I am trying to make a modal corner service. I have a controller that opens some modal ones, in this modal I call the original functions of the controller or get access to some variables, I can do this part already. I just can’t close the modal without pressing the cancel button or ok, o I want to do some operations in modal mode, call some werbservices and close modal manually. Can anybody help me?

I made a working plunker here: plunker

var modalInstance = $modal.open({ templateUrl: 'myModalContent2.html', controller: ModalInstanceCtrl, size: size, scope: $scope }); 
+5
source share
2 answers

To close the $ modal that you opened, you can follow these steps.

1) Add $modalInstance to the controller that you specified when creating the modal. In your case, you named it ModalInstanceCtrl .

2) You have a function in 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(); } }); 
+19
source

 $scope.myData='all data can be'; $scope.myModalInstance = $modal.open({ templateUrl: 'app/myOpen.html', controller: 'myOpenController', size: 'lg', //modal open size large backdrop: 'static', keyboard: false, resolve: { myData: function () { return $scope.myData; } } }); $scope.modalClose = function (){ $scope.myModalInstance.close(); } 
+2
source

Source: https://habr.com/ru/post/1202683/


All Articles