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

Uncaught TypeError: Cannot read property 'apply' of undefined #24

Open
Shrekie opened this issue Apr 17, 2018 · 5 comments
Open

Uncaught TypeError: Cannot read property 'apply' of undefined #24

Shrekie opened this issue Apr 17, 2018 · 5 comments

Comments

@Shrekie
Copy link

Shrekie commented Apr 17, 2018

www-widgetapi.js:48 Uncaught TypeError: Cannot read property 'apply' of undefined

Gets logged every refresh and play, even worse is sometimes the events don't bind. Meaning the playerReady and playerStateChanged don't ever get called. I am unable to see a pattern, but exactly the same code refreshed seems to sometimes result in these events not getting bound. Happens like 10% of the time.

the tags are set up like this:

<ng-youtube-embed 
    video="videoID"
    videoid="videoMainStreamer" 
    enablejsapi="true"
    onready="playerReady"
    onstatechange="playerStateChanged">
</ng-youtube-embed>

The JS is this:

    $scope.videoID = 'VJawYtS_MlE';

    $scope.playerReady = function(event) {
        console.log(event); 
    };

    $scope.playerStateChanged = function(event) {
        console.log(event);
    };

Seems to be a issue of the widgetapi, however this error is avoidable if this module would set up the onYouTubePlayerAPIReady callback in a different way.

Even worse is the events not getting bound sometimes.

@ArunMichaelDsouza
Copy link
Owner

Can you please elaborate, how this is avoidable if we set up the onYouTubePlayerAPIReady callback in a different way ?

@Shrekie
Copy link
Author

Shrekie commented Apr 24, 2018

I think the problem lies mostly in onYouTubeIframeAPIReady not being called in certain circumstances, I would advise you to implement something like this in your module. To forcefully call the function after the iframe has been loaded.

var onLoadEvent = '';

if (!window.onNgYtIframeLoad){
    window.onNgYtIframeLoad = function(){
        window.onYouTubeIframeAPIReady();
    }
}

if(window.onNgYtIframeLoad){
    onLoadEvent = 'onLoad="onNgYtIframeLoad()"'; 
}

var iFrame = '<iframe id=" --etc--  '+ onLoadEvent +'></iframe>';

The pull request from atulingale009 includes very good improvements you should take a look at.

@ArunMichaelDsouza
Copy link
Owner

Hi @Shrekie, I did try to test out the PR but I was facing a few errors -

screen shot 2018-07-14 at 5 28 18 pm

Were you able to make it work by any chance?

@dereekb
Copy link

dereekb commented Aug 5, 2018

PR #23 worked for me, and solved my issue with the API not working for subsequent videos that show up on the page when using ng-if. I haven't run into any new issues yet.

@ArunMichaelDsouza
Copy link
Owner

The PR has been merged. Feel free to try the new version out.

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