themyth92 / ngx-lightbox

Lightbox2 use with angular >= 5
MIT License
115 stars 67 forks source link

Angular 11 Renderer2 issue? #91

Open labago opened 3 years ago

labago commented 3 years ago

I can't seem to get this to work in Angular 11, I have a very basic setup using the instructions in the README but I get the following errors:

image image

Any ideas?

FeliipeAC commented 3 years ago

I manually changed the declarations from Renderer to Renderer2 and this error is gone, but the second error is still

rramsey commented 3 years ago

Angular 12.2.4 w/ ngx-lightbox 2.0.0 here. Changing the import in the lightbox.component.ts and lightbox-overlat.component.ts files worked for me. BUT you have to also change the constructor as well so _rendererRef is an instance of Renderer2.

    import { AfterViewInit, ElementRef, OnDestroy, OnInit, Renderer2 } from '@angular/core';
    ...
    constructor(_elemRef: ElementRef, _rendererRef: Renderer2, _lightboxEvent: LightboxEvent, _lightboxElem: ElementRef, _lightboxWindowRef: LightboxWindowRef, _sanitizer: DomSanitizer, _documentRef: Document);

One I did that, everything worked fine. There could still be an issue with the Renderer methods/properties not matching Renderer2 100%, but at least with a bare minimum app, it compiled.

Renderer2 is supposed to be available with Angular 8, the minimum for ngx-lightbox 2.0.0, so in theory that is all that would need to change. I'd put in a PR for this since it looks like such an easy and simple fix, but I'm not sure what else would break. Maybe I will anyway. The worst that can happen is the devs decline the PR.

Hope that helps.

whizyrel commented 2 years ago

ve you made this PR yet? I am having this issue too

I have the issue you described when I install just 2.0.0, otherwise this error in the image below.

Screenshot from 2021-10-03 15-03-05

For now, I having to remove lightbox because I cannot wait

whizyrel commented 2 years ago

Apparently, what started the issue for me was the latest version 2.5.0, going back to 2.4.1 returned ngx-lightbox to the desired state for me though there was the ".../src/app/app.module.ts depends on 'ngx-lightbox'. CommonJS or AMD dependencies can cause optimization bailouts" warning