bootstrap 5 modal in angular 11 code example
Example: bootstrap 5 with angular modal
ng new appname
npm install — save bootstrap@next
"styles": [
"node_modules/bootstrap/scss/bootstrap.scss",
"src/styles.scss"
],
import Bootstrap from 'bootstrap/dist/js/bootstrap';
modalDirect: Bootstrap.Modal;
@ViewChild('demoModal') input;
open(element): void {
this.modalDirect = new Bootstrap.Modal(element, {});
}
<div class="home-component container">
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary"
(click)="open(demoModal)"
data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>
<!-- Modal -->
<div #demoModal class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
... this is the model content
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>