I made a simple directive that uses the same technique as in J. Bruni's answer.
app.directive('openSingleModal', function() { return { restrict: 'A', link: function(scope, element, attrs) { var opened = false; element.bind('click', function () { if(opened) { return; } opened = true; var modalInstance = scope.$eval(attrs.openSingleModal); if(!modalInstance || !modalInstance.result || typeof modalInstance.result.then !== 'function') { console.error('Incorrect modal instance returned from the open modal function', element, modalInstance); return; } modalInstance.result.then(function () { opened = false; }, function () { opened = false; }); }); } }; });
To switch the code for this directive, just change "ng-click" to "open-single-modal", and the function launched by ng-click should return a modal instance.
Example. Before:
<a ng-click="openModal()">Open Me!</a>
After:
<a open-single-modal="openModal()">Open Me!</a>
and
$scope.openModal = function() { return $uibModal.open(...); };
source share