I will tell you about, Angular 9 – Angular Ngx-Lightbox.
npm i ngx-lightbox
...
{
"styles": [
"node_modules/ngx-lightbox/lightbox.css",
...
],
}
...
import { LightboxModule } from 'ngx-lightbox';
@NgModule({
imports: [ LightboxModule ]
})
import { Lightbox } from 'ngx-lightbox';
export class AppComponent {
_albums = [];
constructor(private _lightbox: Lightbox) {
for (let i = 1; i <= 4; i++) {
const src = 'https://themyth92.com/project/ngx-lightbox/demo/img/image' + i + '.jpg';
const caption = 'Image ' + i + ' caption here';
const thumb = 'https://themyth92.com/project/ngx-lightbox/demo/img/image' + i + '-thumb.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();
}
}
<div *ngFor="let image of _albums; let i=index">
<img [src]="image.thumb" (click)="open(i)" />
</div>
This is it and if you have any kind of query then do comment below.
Originally published by Ajay Malhotra at therichpost.com
#Angular 8 #Angular 9 #Angular7