0

我想将 jquery 简单灯箱:http ://dbrekalo.github.io/simpleLightbox/ 添加到我的应用程序中,我的问题是,当我编写静态代码时效果很好,图像来自链接 = 作品,文件夹中的图像作品,但是当我编写 *ngFor 指令来循环所有图像时,它返回错误并且灯箱未打开但图像正在其他书签中打开。

错误:

Uncaught TypeError: Cannot read property 'addEventListener' of null
at window.onload (fotografia:29)

静态代码工作:

<div class="imageGallery1">
<a href="demo/images/4big.jpg" title="Caption for gallery item 1"><img src="demo/images/4small.jpg" alt="Gallery image 1" /></a>
<a href="demo/images/5big.jpg" title="Caption for gallery item 2"><img src="demo/images/5small.jpg" alt="Gallery image 2" /></a>
<a href="demo/images/6big.jpg" title="Caption for gallery item 3"><img src="demo/images/6small.jpg" alt="Gallery image 3" /></a>
</div>

动态不工作

组件.html:

<div class="imageGallery1">
<a *ngFor="let image of galleryList; let i = index" [href]="image" title="Caption for gallery item {{i + 1}}"><img [src]="image" alt="Gallery image {{i + 1}}" /></a>

galleryList 是一个字符串数组,有 3 个位置,其中包含不同照片的链接

组件.ts:

declare var $: any;
...
ngOnInit() {

$('.imageGallery1 a').simpleLightbox():

}
...
4

1 回答 1

0

您可以在不需要 jQuery 的情况下将 Ngx-Lightbox 与 Angular 一起使用:- https://github.com/themyth92/ngx-lightbox/tree/feature/upgradeAngular7

于 2018-12-01T20:00:14.480 回答