Bootstrap modal not displaying

后端 未结 19 1763
逝去的感伤
逝去的感伤 2020-12-29 01:52

I\'ve copied and pasted the example code from twitter bootstrap to create a basic modal window in my Rails 3.2 app:


相关标签:
19条回答
  • 2020-12-29 02:20

    I tracked down the reason.

    Just to give it some general usefulness to anyone coming to this question. If you can't figure out what's wrong, try doing a 'search all' for any classes of 'modal' 'fade' 'fade in' and 'hide' in any style sheets in your application.

    I had a single instance of 'fade' being defined in a random css file, and that's what was stopping it displaying as it was overriding bootstrap. Once I deleted the reference, everything was ok.

    0 讨论(0)
  • 2020-12-29 02:22

    As Paula, I had the same problem, my modal was not showing, and I realized that my button was in a '< form >' tag ... :

    <button class="btn btn-danger" data-toggle="modal" data-target="#deleteItemModal">Delete</button>
    

    I just replaced < button > by < a >, and my modal worked well

    <a class="btn btn-danger" data-toggle="modal" data-target="#deleteItemModal">Delete</a>
    
    0 讨论(0)
  • 2020-12-29 02:22

    In order to get my modal to display when calling .modal('show')

    I changed:

    modal.on('loaded.bs.modal', function() 
    

    to:

    modal.on('shown.bs.modal', function() {
    
    0 讨论(0)
  • 2020-12-29 02:23

    After encountering this I was surprised to find that none of these solutions worked, as it seems fairly straight forward and I had similar markup working on a different page.

    With my configuration, I had existing jQuery code bound to the same selector triggering the modal. Once starting the process of elimination, all I had to do was comment/remove e.stopPropagation() within my existing script.

    0 讨论(0)
  • 2020-12-29 02:25

    If you are using angular and trying to create a directive that has a custom modal in it, the modal backdrop will show but the modal itself will not unless you set replace: true on your directive.

    Typescript Directive:

    export class myModalDirective implements ng.IDirective {
        static Register = () => {
            angular.module('app').directive('myModal', () => { return new myModalDirective () });
        }
        templateUrl = 'mymodal.html'    
    restrict = 'E';
        replace = true;
        scope = {
            show: '='
        }
        link = (scope: any, element: ng.IAugmentedJQuery, attrs: ng.IAttributes, ctrl: any) => {
            var vm = this;
            scope.$watch(function () { return scope.show; }, function (vis) {
                if (vis) {
                    $(element).modal('show');
                } else {
                    $(element).modal('hide');
                }
            });
    
        }
        constructor () {
        }
    }
    

    Modal HTML

    <div class="modal fade" data-keyboard="false" data-backdrop="static">
        <div class="modal-dialog">
            <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title">Modal Title</h4>
                    </div>
                    <div class="modal-body">
                    </div>
            </div>
        </div>
    </div>
    
    0 讨论(0)
  • 2020-12-29 02:25

    You are supposed to import jquery and bootstrap.min.js.

    Add this to angular-cli:

    "scripts": ["../node_modules/jquery/dist/jquery.min.js",
            "../node_modules/bootstrap/dist/js/bootstrap.min.js"]
    

    make sure you have its folders.

    0 讨论(0)
提交回复
热议问题