Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap-ui modal not showing the grey background behind it, (modal-backdrop class is not added on open)

for some reason my modal is opened without the grey background although i'm using the same code as in there website : http://angular-ui.github.io/bootstrap/#/modal
the only difference is that i used a template from separated html file and not inside a <script> tag.

i noticed that its not adding this code: <div class="modal-backdrop fade in"></div> inside the main modal container <div class="modal fade in">

like image 309
Haitham Zoabi Avatar asked Feb 14 '15 21:02

Haitham Zoabi


People also ask

How do I show a Bootstrap modal inside a div?

To show a bootstrap modal inside a div the logic behind the above code is to append the HTML code of the modal as well as the modal-backdrop inside that specific div(blue div whose position is relative) and then making the CSS for modal and modal-backdrop to position:absolute so that the modal and its background gets ...

How do I remove modal overlay?

How do I remove modal overlay? Add data-backdrop="false" option as attribute to the button which opens the modal. Save this answer.

How do I stop the background when modal windows pop up?

The key idea is to have pointer-events: none; for the body when modal is open. But the specific elements you want to be interacted with should have e.g. pointer-events: auto; . In the example you can click both buttons when dialog is hidden, but only Toggle Dialog button when dialog is shown.

What is backdrop in Bootstrap modal?

The backdrop option specifies whether the modal should have a dark overlay (the background color of the current page) or not.


3 Answers

The problem is that original backdrop has 0px height, to fix add the following style:

<style>
    .modal-backdrop {
        height: 100%;
    }
</style>

The advantage of this solution over accepted one is that you do not loose dismiss clicking on backdrop.

If you don't like when backdrop dismiss modal add the following to $modal.open:

$modal.open({
    ...
    backdrop: 'static',
    ...
like image 185
Skarllot Avatar answered Oct 10 '22 04:10

Skarllot


fixed,
i added windowTemplateUrl to the $modal.open({..}) options object
which overrides the modal main window : https://github.com/angular-ui/bootstrap/blob/master/template/modal/window.html

so the open code looks like this:

var modalInstance = $modal.open({
      templateUrl: 'myModalContent.html',
      controller: 'ModalInstanceCtrl',
      windowTemplateUrl: 'modalWindowTemplte.html'
      ...
    });

and the override template now forced to included the div.modal-backdrop

<script type="text/ng-template" id="modalWindowTemplte.html">
        <div tabindex="-1" role="dialog" class="modal fade" ng-class="{in: animate}" ng-style="{'z-index': 1050 + index*10, display: 'block'}">
            <div class="modal-backdrop fade in"></div>
            <div class="modal-dialog" ng-class="{'modal-sm': size == 'sm', 'modal-lg': size == 'lg'}"><div class="modal-content" modal-transclude></div></div>
        </div>
    </script>
like image 30
Haitham Zoabi Avatar answered Oct 10 '22 04:10

Haitham Zoabi


add this class to options in open function: 'backdropClass : 'modal-backdrop h-full' like this:

var modalInstance = $modal.open({
      templateUrl: 'myModalContent.html',
      controller: 'ModalInstanceCtrl',
      backdropClass  : 'modal-backdrop h-full',
      ...
});
like image 27
Jose Gustavo Avatar answered Oct 10 '22 04:10

Jose Gustavo