Monday, May 20, 2024
Angular 8Bootstrap 4

Angular 8 enlarge image in custom bootstrap modal

Angular playing api data

Hello to all, welcome again on In this post, I will tell you, Angular 8 enlarge image in custom bootstrap modal.

This example is with my own thought and may be it will be helpful to someone.

Angular 8 enlarge image in custom bootstrap modal
Angular 8 enlarge image in custom bootstrap modal

Here is the complete working steps and please do it very carefully:

1. Here are the basics commands to install angular 8 on your system:

npm install -g @angular/cli 

ng new angularpopup //Create new Angular Project

$ cd angularpopup // Go inside the Angular Project Folder

ng serve --open // Run and Open the Angular Project

http://localhost:4200/ // Working Angular Project Url


2. After done with above, you need to run below commands to set bootstrap environment into your angular 8 application:

npm install --save bootstrap


3. Now you need to add below code into your angular.json file:

"styles": [
            "scripts": ["node_modules/bootstrap/dist/js/bootstrap.min.js"]


4. Now you need to add below code into your src/app/app.component.ts file:

import { Component } from '@angular/core';
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
export class AppComponent {
  title = 'angulartoastr';
  showModal: boolean;
    this.showModal = true; // Show-Hide Modal Check
  //Bootstrap Modal Close event
    this.showModal = false;



5. Now you need to add below code into src/app/app.component.html file:

<a href="#" (click) = "show()">
  <img id="imageresource" src="" style="width: 125px; height: 125px;">
  Click to Enlarge
<!-- Creates the bootstrap modal where the image will appear -->
<div [style.display]="showModal ? 'block' : 'none'" class="modal" id="imagemodal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
  <div class="modal-content">
    <div class="modal-header">
      <h4 class="modal-title" id="myModalLabel">Image preview</h4>
    <div class="modal-body">
      <img src="" id="imagepreview" style="width: 425px; height: 425px;" >
    <div class="modal-footer">
      <button type="button" class="btn btn-default" data-dismiss="modal" (click) = "hide()">Close</button>


In the end please run ng serve command to taste the output. If you have any query then please comment below.


Thank you

the authortherichpost
Hello to all. Welcome to Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.