Open In App
Related Articles

How to open popup using Angular and Bootstrap ?

Like Article
Save Article
Report issue
Adding Bootstrap to your Angular application is an easy process. Just write the following command in your Angular CLI. It will add bootstrap into your node_modules folder.
ng add @ng-bootstrap/ng-bootstrap
Approach: Import NgbModal module in the TypeScript file of the corresponding component, and then we have to write code for the popup model by using the above module in the HTML file of the corresponding component. Syntax:
  • In typescript file:
    import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
  • In html file:
    <ng-template #content let-modal>
Example: modal-basic.ts
import {Component} from '@angular/core';
import {NgbModal, ModalDismissReasons} 
      from '@ng-bootstrap/ng-bootstrap';
  selector: 'ngbd-modal-basic',
  templateUrl: './modal-basic.html'
export class NgbdModalBasic {
  closeResult = '';
  constructor(private modalService: NgbModal) {}
  open(content) {,
   {ariaLabelledBy: 'modal-basic-title'}).result.then((result) 
      => {
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
      this.closeResult = 
         `Dismissed ${this.getDismissReason(reason)}`;
  private getDismissReason(reason: any): string {
    if (reason === ModalDismissReasons.ESC) {
      return 'by pressing ESC';
    } else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
      return 'by clicking on a backdrop';
    } else {
      return `with: ${reason}`;

Now, we have to use ng-template to construct the model which will create a popup. Example: modal-basic.html
<ng-template #content let-modal>
    <div class="modal-header">
        <h4 class="modal-title" 
            Geeks of Geeks
        <button type="button" class="close"
                aria-label="Close" (click)=
                "modal.dismiss('Cross click')">
            <span aria-hidden="true">
    <div class="modal-body">
            <div class="form-group">
                <label for="dateOfBirth">
                    Date of birth
                <div class="input-group">
                    <input id="dateOfBirth" 
                        name="dp" ngbDatepicker
                    <div class="input-group-append">
                        <button class="btn 
                            btn-outline-secondary calendar"
    <div class="modal-footer">
        <button type="button" 
            class="btn btn-outline-dark" 
            (click)="modal.close('Save click')">
<button class="btn btn-lg btn-outline-primary" 
    Popup using Angular and Bootstrap


Last Updated : 31 May, 2020
Like Article
Save Article
Share your thoughts in the comments
Similar Reads