I\'ve copied and pasted the example code from twitter bootstrap to create a basic modal window in my Rails 3.2 app:
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.
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>
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() {
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.
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>
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.