I am using the Angular UI bootstrap modal dialog and create it within a service:
myApp.factory('ModalService', ['$modal', function($modal) { return { trigger: function(template) { $modal.open({ templateUrl: template, size: 'lg', controller: function($scope, $modalInstance) { $scope.ok = function() { $modalInstance.close($scope.selected.item); }; $scope.cancel = function() { $modalInstance.dismiss('cancel'); }; } }); }, close: function() { // this should close all modal instances } }; }]);
How can I close all modal instances when calling ModalService.close()
from a controller or whatsoever?
Opening & Closing Angular 8 Modal Dialogs open('custom-modal-1') . To close a modal call the modalService. close() method with the id of the modal you want to close, e.g. modalService. close('custom-modal-1') .
$uibModal is a service to create modal windows. It has an open method, that will return a modal instance. Show activity on this post. It is a service for opening modals in AngularJs.
Inject the $modalStack
service and call the function $modalStack.dismissAll()
, see the code on GitHub for details:
myApp.factory('ModalService', ['$modal', '$modalStack' function($modal, $modalStack) { return { trigger: function(template) { $modal.open({ templateUrl: template, size: 'lg', controller: function($scope, $modalInstance) { $scope.ok = function() { $modalInstance.close($scope.selected.item); }; $scope.cancel = function() { $modalInstance.dismiss('cancel'); }; } }); }, close: function(reason) { $modalStack.dismissAll(reason); } }; }]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With