Angular Bootstrap modal is not working in Ngfor

Viewed 561

I am using Angular 8, In this I need to do a popup in NgFor loop, the data is binding in popup modal but the same data is binding continously in the bootstrap modal...

My Html is

<tr *ngFor="let law of List; index as i">     
     <td>{{i+1}}</td>
     <td>
          <mat-form-field>
          <input matInput placeholder="Name" [formControl]="college">
          </mat-form-field>
     </td>
     <td>
           <button type="button" class="btn btn-primary"
            data-toggle="modal" data-target=".bd-example-modal-lg" (click)="data(law )"
             (click)="get()">Quantity</button>
     </td>
</tr>

<div class="modal fade bd-exampletwo-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
   <div class="modal-dialog modal-lg">
      <div class="modal-content">
          <div class="modal-header">
            <h2 class="modal-title" id="exampleModalLabel">Delivary Details</h2>
               <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                 <span aria-hidden="true">&times;</span></button>
         </div>
             <div class="modal-body">
                  <div>
                     <table ">
                        <thead>
                            <tr>
                              <th>Sl.No</th>
                                 <th>first Name</th>
                              </tr>
                        </thead>
                    <ng-container>
                         <tr [formGroupName]="j">
                              <td>{{j+1}}</td>
                              <td>
                               <td>      
                                <mat-form-field>
                                  <input matInput placeholder="firstname" formControlName="f_name</mat-form-field>
                               </td>
                        </tr>
                     </ng-container>    
                  </table>
                 </div>
                </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
              </div>
               </div>
                  </div>
                    </div>


How to iterate the bootstrap modal in ngfor .. In this same data is binding again and again..

data-target=".bd-exampletwo-modal-lg{{i}}">

<div class="modal-dialog modal-lg" id="{{i}}"></div

I used this to iterate but not working How to Do that

1 Answers

Bootstrap's JavaScript-based components, such as modal, do not work correctly with Angular. It is best to use an Angular-specific library, such as ng-bootstrap or ngx-bootstrap.

Related