I am trying to use a Bootstrap modal in an Angular application using classes in HTML, but it not working – its not showing as a modal
<div class="modal text-center" *ngIf="showmodal" tabindex="-1" id="withScrollExampleModal">
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title fw-normal">Basic dialogue title</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">
<i class="fa-light fa-circle-xmark"></i>
</button>
</div>
<div class="modal-body f-14">
<p>Lorem ipsum dolor sit amet consectetur. Enim libero commodo nibh vitae sed laoreet magna dui pharetra.
</p>
</div>
<div class="modal-footer d-flex justify-content-center">
<button type="button" class="btn btn-secondary rounded-pill" data-bs-dismiss="modal">Action 1</button>
<button type="button" class="btn btn-outline-primary rounded-pill">Action 2</button>
</div>
</div>
</div>
</div>
2
Answers
Bootstrap has build in functions to open and close modals.
For example there is a button that should open a modal, in that button there needs to be a data toggle like
data-toggle="modal"
and the target id of the modal likedata-target="#Id of the modal"
Further the modal itself hass to have a class called "modal" and a id. This id has to be the same as the data-target.
Here is an example of a modal.
For this to work make sure to import the following items in the head
For more information on modals in bootstrap go to the following link
https://getbootstrap.com/docs/4.0/components/modal/
I don’t think it’s a good idea to use bootstrap with just css. If you do absolutely want to do that, you can try this
You need to add the
show
css class on the modal and also setdisplay: block
on that div. But without the js, you won’t see the transitions, the backdrop or dismiss the model.Bootstrap suggests using https://ng-bootstrap.github.io/ if you’re using it in angular