Categories

Sunday, December 22, 2024
#919814419350 therichposts@gmail.com
Angular 8Angular 9Angular7

Angular 9 – Angular Ngx-Lightbox

Angular Lightbox Working Tutorial

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

angular lightbox
angular lightbox

Angular 14 came and if you are new then you must check below link:

  1. Angular14 Basic Tutorials

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": [
    "node_modules/ngx-lightbox/lightbox.css",
    ...
  ],
}
...

 

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

import { LightboxModule } from 'ngx-lightbox';
 
@NgModule({
  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:any = [];
  constructor(private _lightbox: Lightbox) {
    for (let i = 1; i <= 3; i++) {
      const src = 'https://therichpost.com/wp-content/uploads/2021/05/bootstrap5-carousel-slider-img' + i + '.jpg';
      const caption = 'Image ' + i + ' caption here';
      const thumb = 'https://therichpost.com/wp-content/uploads/2021/05/bootstrap5-carousel-slider-img' + i + '.jpg';
      const album = {
         src: src,
         caption: caption,
         thumb: thumb
      };
 
      this._albums.push(album);
    }
  }
 
  open(index: number): void {
    // open lightbox
    this._lightbox.open(this._albums, index);
  }
 
  close(): void {
    // close lightbox programmatically
    this._lightbox.close();
  }
}

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 width="100" [src]="image.thumb" (click)="open(i)" />
</div>

 

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

Jassa

Thank you

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

11 Comments

Leave a Reply

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