python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 7, Interview Questions Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
Angular 5 Modal Popup

Angular 5 and 4 - Open and Close Modal Popup Using Typescript and Bootstrap

How to Create a Modal Popup for Angular 5 and 4?

Two ways to CREAT Modal Popup Window -
1.      Modal Popup using Typescript and Bootstrap
2.      Modal Popup using Angular Material Dialogue

Open Modal Popup Using Typescript and Bootstrap
Download and use the Bootstrap CDN to deliver Bootstrap's compiled CSS and JS to your project.

Steps 1 – Add Bootstrap CSS and Js files in the AppComponent.HTML file.
<link rel="stylesheet" href=""  crossorigin="anonymous">
<script src=""  crossorigin="anonymous"></script>

You can also Install Bootstrap from NPM –
npm install bootstrapsave

Steps 2 – Add Style CSS for Login and Popup validations and it looks like.
.ng-valid[required], .ng-valid.required  {
    font-size: 16px;
    text-align: center;
    text-decoration: none;
    border-left: 10px solid rgb(218, 200, 43); /* yellow */

.ng-invalid:not(form)  {
    font-size: 16px;
    text-align: center;
    text-decoration: none;
    border-left: 10px solid #e94646; /* red */

.backdrop {

Steps 3 – Added HTML for Open Popup – header, content body and footer to display and it looks like.
<!-- After clicking the button open the modal dialog using open/close event binding methods -->
<button type="button" class="btn btn-info btn-lg" (click)="closeModalDialog()">Open Login Modal Dialog!</button>
<div class="backdrop" [ngStyle]="{'display':display}"></div>

<!-- modal -->
<div class="modal" tabindex="-1" role="dialog"  [ngStyle]="{'display':display}">
  <!-- modal-dialog -->
  <div class="modal-dialog" role="document">
    <!-- modal-content -->
    <div class="modal-content">
      <!-- modal-header -->
      <div class="modal-header">
        <button type="button" class="close" aria-label="Close" (click)="openModalDialog()"><span aria-hidden="true">&times;</span></button>
        <!-- <h4 class="modal-title">Login</h4> -->

      <!-- modal-body -->
      <div class="modal-body">
        <form [formGroup]="logedInForm" (ngSubmit) = "mdfLogin(logedInForm.value)" >
                <input type="text" class="textbox" name="emailId" placeholder="Email" formControlName="emailId">
                <input type="password" class="textbox" name="password" placeholder="password" formControlName="password">
                <input type="submit" class="btn btn-info btn-lg" value="LogIn" [disabled] = "!logedInForm.valid">
                <p>EmailId Is  - {{emailId}} and Password is - {{password}}</p>

      <!-- modal-footer -->
      <div class="modal-footer">
        <button type="button" class="btn btn-default" (click)="closeModalDialog()" >Close</button>

In the above HTML, the methods openModalDialog() is used for open the popup and the  method closeModalDialog() is for close popup and also method mdfLogin() is used for submit the login form.

Steps 4 - The Events looks like – user.component.ts
import { Component, OnInit } from '@angular/core';
import {FormGroup, FormControl, Validators}  from '@angular/forms';
import { stringify } from '@angular/core/src/render3/util';
import { variable } from '@angular/compiler/src/output/output_ast';

  selector: 'app-user',
  templateUrl: './user.component.html',
  styleUrls: ['./user.component.css']
export class UserComponent implements OnInit {
  date; //date Variable
  logedInForm; //These are variables
  display='none'; //default Variable

  constructor() { }

  ngOnInit() { = new Date(); // Today date and time
    //Login Validation
    this.logedInForm = new FormGroup({
      emailId: new FormControl("[email protected]",
          Validators.pattern("[^ @]*@[^ @]*")
      password: new FormControl('YourPassword', [

  // Model Driven Form - login
  mdfLogin(data) {
    this.emailId = data.emailId;
    this.password = data.password;

    this.display='block'; //Set block css

  this.display='none'; //set none css after close dialog

The result looks like –

The Video link is -
I hope you are enjoying with this post! Please share with you friends. Thank you so much!

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - and
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like Powered by Blogger.
ASK Questions