showing results for - "bootstrap 5 with angular modal"
Mattia
28 Oct 2018
1//Generate an angular project using 
2//ng command and then install the bootstrap 5 alpha by 
3ng new appname 
4npm install — save bootstrap@next
5
6
7//Now add the `scss/css`
8//to your angular.json file 
9//to include the bootstrap css classes to your app
10
11"styles": [
12  "node_modules/bootstrap/scss/bootstrap.scss",
13  "src/styles.scss"
14],
15
16//Import Boostrap in your component
17import Bootstrap from 'bootstrap/dist/js/bootstrap';
18
19// Define a variable for bootstrap modal and @ViewChild like below
20modalDirect: Bootstrap.Modal;
21@ViewChild('demoModal') input;
22
23//Now create a method to open the bootstrap5 modal on click of a button
24open(element): void {
25  this.modalDirect = new Bootstrap.Modal(element, {});
26}
27
28// Example HTML FILE
29<div class="home-component container">
30  <!-- Button trigger modal -->
31  <button type="button" class="btn btn-primary"
32          (click)="open(demoModal)"
33          data-toggle="modal" data-target="#exampleModal">
34    Launch demo modal
35  </button>
36
37  <!-- Modal -->
38  <div #demoModal class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
39    <div class="modal-dialog">
40      <div class="modal-content">
41        <div class="modal-header">
42          <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
43          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
44            <span aria-hidden="true">&times;</span>
45          </button>
46        </div>
47        <div class="modal-body">
48          ... this is the model content
49        </div>
50        <div class="modal-footer">
51          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
52          <button type="button" class="btn btn-primary">Save changes</button>
53        </div>
54      </div>
55    </div>
56  </div>
57</div>