Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Bootstrap Modal leaves backdrop open

I'm using AngularUI to integrate Bootstrap components in my Angular 1.4 app, such as Modals.

I'm calling a Modal in my controller like so:

var modalInstance = $modal.open({
  animation: true,
  templateUrl: '/static/templates/support-report-modal.html',
  controller: 'ModalInstanceCtrl'
});

Unfortunately, when I want to close the Modal by using:

modalInstance.close();

The modal itself dissapears, and the backdrop also fades out, but it isn't removed from the DOM, so it overlays the whole page leaving the page unresponsive.

When I inspect, I'm seeing this:

enter image description here

In the example in the Documentation on https://angular-ui.github.io/bootstrap/#/modal The class modal-open is removed from body and the whole modal-backdropis removed from the DOM on close. Why is the Modal fading out but the backdrop not removed from the DOM in my example?

I've checked out many of the other questions about the backdrop of bootstrap Modals but I can't seem to figure out what's going wrong.

like image 455
Squrler Avatar asked May 12 '15 12:05

Squrler


People also ask

How do I close modal backdrop?

Modals are built with HTML, CSS, and JavaScript. They're positioned over everything else in the document and remove scroll from the <body> so that modal content scrolls instead. Clicking on the modal “backdrop” will automatically close the modal.

How do I stop bootstrap modal from opening?

Add some kind of identifier for the item you don't want to trigger the modal, a class like no-modal for example, then in your jQuery add code for the modal's show. bs. modal event. Capture the relatedElement, which is the element that triggered the event, then see if it has the class you're looking for.

How do I make modal background not close on click outside?

Data-keyword="false" is to prevent closing modal while clicking Esc button, while data-backdrop="static" , allows you keep modal pop-up opened when clicking on Gray area.


Video Answer


2 Answers

This is apparently due to a bug. AngularUI doesn't support Angular 1.4 yet. Once http://github.com/angular-ui/bootstrap/issues/3620 is resolved this will work.

like image 193
Squrler Avatar answered Oct 17 '22 04:10

Squrler


Until the team gets this sorted here is a work around.

<div class="modal-footer">
    <button class="btn btn-primary"
        ng-click="registerModal.ok()"
        remove-modal>OK</button>
    <button class="btn btn-warning"
        ng-click="registerModal.cancel()"
        remove-modal>Cancel</button>
</div>

/*global angular */
(function () {
'use strict';
angular.module('CorvetteClub.removemodal.directive', [])
.directive('removeModal', ['$document', function ($document) {
    return {
        restrict: 'A',
        link: function (scope, element, attrs) {
            element.bind('click', function () {
                $document[0].body.classList.remove('modal-open');
                    angular.element($document[0].getElementsByClassName('modal-backdrop')).remove();
                    angular.element($document[0].getElementsByClassName('modal')).remove();
                });
            }
        };
    }]);
}());

Unfortunately it appears that the team is not on the same page concerning this issue as it was pushed to a separate thread by a contributor and then the thread it was pushed to was closed by another as it was considered "off topic" by another.

like image 36
tuckerjt07 Avatar answered Oct 17 '22 05:10

tuckerjt07