Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'this' reference is undefined #141

Closed
GeorgeKnap opened this issue Jun 10, 2019 · 2 comments
Closed

'this' reference is undefined #141

GeorgeKnap opened this issue Jun 10, 2019 · 2 comments

Comments

@GeorgeKnap
Copy link

I am using screenfull.js 4.2.0 in Angular app and I'm curious if anyone encountered my situation as I'm running out of ideas.

this is how I use this library in one of my component:

import * as screenfull from 'screenfull';
import { Screenfull } from 'screenfull';

const sf = screenfull as Screenfull;
 if (sf.enabled) {
      sf.toggle(someElement);
    }

Everything works fine when it's served for development via ng serve.
However, when built via ng build --prod I'm getting runtime error TypeError: Cannot read property 'isFullscreen' of undefined.
Capture

@1615450788
Copy link

4.0.1 is normal

@sindresorhus
Copy link
Owner

Screenfull is an object, and its methods are not individual exports, so when you try to import each method individually with import * as screenfull from 'screenfull';, you lose the this binding. The correct way to import it is import screenfull = require('screenfull');.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants