Angular 8Angular 9Angular7

Angular 9 – Angular Ngx-Lightbox

Angular Lightbox Working Tutorial

Hello to all, welcome to In this post, I will tell you about, Angular 9 – Angular Ngx-Lightbox.

angular lightbox
angular lightbox

Here are the working commands and code snippet, please follow carefully:

1. Here is the command you need to run to install lightbox module into your angular 9 application:

npm i ngx-lightbox

2. Here is the code you need to add your angular.json file:

  "styles": [

3. Here is the code you need to add into your app.module.ts file:

import { LightboxModule } from 'ngx-lightbox';
  imports: [ LightboxModule ]

4. Here is the code you need to add into your app.component.ts file:

import { Lightbox } from 'ngx-lightbox';
export class AppComponent {
  _albums = [];
  constructor(private _lightbox: Lightbox) {
    for (let i = 1; i <= 4; i++) {
      const src = '' + i + '.jpg';
      const caption = 'Image ' + i + ' caption here';
      const thumb = '' + i + '-thumb.jpg';
      const album = {
         src: src,
         caption: caption,
         thumb: thumb
  open(index: number): void {
    // open lightbox, index);
  close(): void {
    // close lightbox programmatically

5. Here is the code you need to add into your app.component.html file:

<div *ngFor="let image of _albums; let i=index">
  <img [src]="image.thumb" (click)="open(i)" />

This is it and if you have any kind of query then do comment below.


Thank you

Ajay Malhotra
the authorAjay Malhotra
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 2, Angular 6, Angular 7, Angular 8, Angular 9, Angular 10, Angular 11, Nodejs, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.


  • First i want to say thank you for the tutorial it was straight forward an fairly simple. When i use your link with images the code seems to work, however when i try to change the src location the images does not appear. Also i have jpg and png photos in this location how can i use both.

Leave a Reply

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