javascripthtmlcssangularng2-bootstrap

How to get popup window using ng2-bootstrap?


<section class="main">
 <h1>Company Management</h1>
 <md-card>
   <button class="md-fab md-mini add-task" md-mini-fab title="Add" (click)="addCompany.show()">
    <md-icon style="color:white;">add</md-icon>
   </button>
      <div class="table-responsive">
     <table class="table adminTable">
       <thead>
         <th>Name</th>
         <th>Email</th>
         <th>country</th>
         <th>Action</th>
       </thead>
       <tbody>
         <tr *ngFor="let company of companies">
           <td>{{company.user_name}}</td>
           <td>{{company.email}}</td>
           <td>{{company.country}}</td>
           <td>
               <button class="btn" md-raised-button>Guide</button>
               <button class="btn" md-raised-button>Pin</button>
               <button class="iconBtn first">
                <i class="fa fa-pencil" aria-hidden="true"></i>
               </button>
               <button class="iconBtn second">
                 <i class="fa fa-trash-o" aria-hidden="true"></i>
               </button>
           </td>
         </tr>
       </tbody>
     </table>
   </div>
 </md-card>
</section>
<div bsModal #addCompany="bs-modal" class="modal fade " tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-md">
  <div class="modal-content">
     <div class="modal-body">
     
     </div>
     <div class="modal-footer cat-btn">
       <button md-raised-button class="md-raised cancel color-white" (click)="addCompany.hide()">Cancel
       </button>
       <button md-raised-button class="md-raised save color-white">Save</button>
     </div>
   </div>
 </div>
</div>

this my html code where i used ngmodal for popup window but im not getting any kind of popup model. i have imported import { ModalModule } from 'ng2-bootstrap'; in the app.module.ts file can u please help me out to fix this problem


Solution

  • Your code is 100% fine, there is no issue on template side.

    But The Possible issues might be:

    1) Imported just ModalModule rather than ModalModule.forRoot()

    import { ModalModule } from 'ngx-bootstrap';
    
    @NgModule({
      imports:      [ ... , ModalModule.forRoot() ],
      ...
    })
    

    2) Forgot to add css


    Here is the working example of static modal, you can compare your code wiht this :

    https://stackblitz.com/edit/angular-ngx-bootstrap