Reputation: 177
I want to display a modal on button click, but the modal doesn't display.
I specified the modal as data-target for a button and I don't get anything and there are no errors on console either.
<button type="submit" data-toggle="modal" data-
target="#someModal">Test</button>
<!-- Modal -->
<div class="modal fade" id="someModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×
</button>
</div>
<div class="modal-body">
<p>Modal text</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-
dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
This code is in my component.html page.
Upvotes: 1
Views: 433
Reputation: 165
You have some empty spaces after data-
and before target
. Just put them on the same line and it works. Same goes for data-dismiss
for the close button.
Also, I'd remove type="submit"
since it's not required by the official docs: Modal - Bootstrap.
Here is the working code:
<button data-toggle="modal" data-target="#someModal">Test</button>
<!-- Modal -->
<div class="modal fade" id="someModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<p>Modal text</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Upvotes: 1
Reputation: 2567
I think you have not added JQuery
.So that I have your code by adding bootstrap JQuery
and its working.
<html>
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</head>
<body>
<button type="submit" data-toggle="modal" data-target="#someModal" class="btn btn-danger">Test</button>
<!-- Modal -->
<div class="modal fade" id="someModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×
</button>
</div>
<div class="modal-body">
<p>Modal text</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-
dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</body>
</html>
To install bootstrap JQuery check this How to add JQuery to Angular Thanks
Upvotes: 0