brandly / angular-youtube-embed

:tv: Embed a YouTube player with a simple directive

Home Page:http://brandly.github.io/angular-youtube-embed/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

getIdFromURL try in to replace from null url

thiago14 opened this issue · comments

Console error starting directive with 'Video url' because it loads before the variable. One possible solution would be to add an 'if' before the methods.

start at line 212
scope. $ watch ('videoURL', function (url) {
    if (url! == null)
    {
         scope.videoId = scope.utils.getIdFromURL (url);
         scope.urlStartTime = scope.utils.getTimeFromURL (url);

         loadPlayer ();
    }
});

I had the same problem right now and added those lines. I think that the directive needs some unloaded/idle state or a way of handling null urls.

in what situation are you setting videoUrl to null? an unset variable will be undefined, so we check for that internally. i think the directive should assume you're only handing it URLs, and your application code should ensure that it's only handling URLs.

like, i think you should see an error in your console if your application code is producing null values and handing it to the directive. if i put an if statement like that in the code, the directive would swallow the error, making it more difficult to debug the errant application.

if there's a situation where you think this directive misbehaves, could you demonstrate it with a JSFiddle or something similar?

^ to be clear, i'm saying "this is my opinion," but i'm open to more feedback 😄

@brandly Oh, I didn't know that the script checks for undefined. I am using null to mark "unset url state", so I guess I will have to change it to undefined and my problem will go away.

It works with 'undefined', thanks