DEV Community 👩‍💻👨‍💻

Discussion on: Switch themes like a fox 🦊 based on Ambient Light 💡 in your Angular Apps

stephaneeybert profile image
Stephane Eybert • Edited on

Hello !
Very interesting article. I implemented it in a PWA I'm doing. I can see your stackblitz is showing the AmbientLightSensor class is undefined. The same was happening in my VSCode IDE I can say.

I could solve it by adding the following source code above the service class:
declare global {
interface Window {
AmbientLightSensor: any;
And injecting the window: Window object in the constructor, I then could do:
const sensor: any = new this.window.AmbientLightSensor();

Kind Regards,
Stephane Eybert