themyth92 / ngx-lightbox

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

standalone component: No provider for LightboxWindowRef! #160

Open pierresh opened 6 months ago

pierresh commented 6 months ago

I cannot use ngx-lightbox in standalone component with Angular 15.

However, I imported LightboxModule in my component.

I get the following error:

attachments.service.ts:100 ERROR NullInjectorError: R3InjectorError(Environment Injector)[LightboxWindowRef -> LightboxWindowRef]: 
  NullInjectorError: No provider for LightboxWindowRef!
    at NullInjector.get (core.mjs:7493:27)
    at R3Injector.get (core.mjs:7914:33)
    at R3Injector.get (core.mjs:7914:33)
    at ChainedInjector.get (core.mjs:12084:36)
    at lookupTokenUsingModuleInjector (core.mjs:3201:39)
    at getOrCreateInjectable (core.mjs:3246:12)
    at Module.ɵɵdirectiveInject (core.mjs:10041:12)
    at NodeInjectorFactory.LightboxComponent_Factory [as factory] (lightbox.component.js:568:272)
    at getNodeInjectable (core.mjs:3431:44)
    at createRootComponent (core.mjs:12297:35)
autumnesponda commented 4 months ago

in case anyone else stumbles upon this, make sure the dependency is injected in the constructor as public; at least that's what solved the problem for me.

    constructor(public _lightbox: Lightbox, public _lightboxConfig: LightboxConfig) { }