angularngx-modal

ngx-modal - Angular 2


I am trying to implement modal form in my angular application. My code looks alright to me as i do not see any error. I have installed ngx-modal into my application and i have also imported the ModalModule in my app.module.ts file. What could be the reason why the modal form is not responding?

<button class="btn btn-success"  data-toggle="modal" data-target="#myModal">Open</button>

<div class="modal fade" id="myModal" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">

          <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>
      <div class="modal-body">
</div>
      </div>
    </div>
  </div>
</div>

app.module.ts

import {ModalModule} from 'ngx-modal';

imports: [          
        ModalModule,
],

Solution

  • you have required to open your modal with

    <button (click)="myModal.open()">open my modal</button>
    <modal #myModal>
        <modal-header>
            <h1>Modal header</h1>
        </modal-header>
        <modal-content>
            Hello Modal!
        </modal-content>
        <modal-footer>
          <button class="btn btn-primary" (click)="myModal.close()">&times;</button>
        </modal-footer>
    </modal>