Hey everyone! I'm facing an issue with Angular Material Dialog and Fancybox slider integration. When I click the Fancybox close button, it closes BOTH the Fancybox slider AND my Material Dialog component. I only want it to close the Fancybox slider, not the entire dialog.
`export class NewsDetailDialogComponent implements OnInit, OnDestroy {
@ViewChild('sliderRef', { static: false }) sliderRef!: ElementRef;
videoUrls: string[] = [];
constructor(
@Inject(MAT_DIALOG_DATA) public data: NewsResponse,
public dialogRef: MatDialogRef<NewsDetailDialogComponent>,
) {
if (this.data?.videos?.length) {
this.videoUrls = this.data.videos.map((v: any) => v.url);
}
}
ngAfterViewInit(): void {
Fancybox.bind(this.sliderRef.nativeElement, '[data-fancybox="gallery"]', {
Html: {
videoAutoplay: false,
},
});
}
ngOnDestroy(): void {
Fancybox.unbind(this.sliderRef.nativeElement);
Fancybox.close();
}
}`
`<h2 mat-dialog-title>
<span>News Details</span>
<button class="dialog-close-btn" mat-dialog-close>
<app-svg type="close" />
</button>
</h2>
<mat-dialog-content>
<div class="news-gallery" #sliderRef>
@for (item of data.images; track $index) {
<a [href]="item.url" data-fancybox="gallery" class="gallery-item">
<img [src]="item.url" alt="Gallery image" />
</a>
}
@for (url of videoUrls; track $index) {
<a [href]="url" data-fancybox="gallery" data-type="html5video">
<video [src]="url" preload="metadata" [muted]="true"></video>
</a>
}
</div>
</mat-dialog-content>`
Has anyone successfully integrated Fancybox (or similar lightbox libraries) inside an Angular Material Dialog? How do you prevent the lightbox close button from closing the parent dialog? Any help would be greatly appreciated! π
"@angular/material": "~19.2.10", "@fancyapps/ui": "^5.0.36", "@angular/cli": "^19.2.9",