[Fixed][1.0.0-beta.10] Youtube iframe not working


<div class="video-container" ng-bind-html="mediaIframe"></div>


        if($scope.post.uuid.substr(0, 3) == 'ut_') {
            var videoWidth = bodyWidth - 20;
            var videoUrl = 'http://www.youtube.com/embed/'+$scope.post.uuid.substr(3)+'?rel=0';
            $scope.mediaIframe = '<iframe width="'+videoWidth+'" height="200" src="'+$sce.trustAsResourceUrl(videoUrl)+'" frameborder="0" allowfullscreen> </iframe>';
        } else {
            $scope.mediaIframe = "";

It ends up only with an empty div. The console goes OK:

<iframe width="300" height="200" src="http://www.youtube.com/embed/BjJpNFRHxKg?rel=0" frameborder="0" allowfullscreen> </iframe>

Hmm, seems like case of CROS. Have you whitelist the url in your config setup?

I learned this the hard way

You mean the $sce.trustAsResourceUrl(videoUrl)part?

It’s a bit more detailed than that, but yeah thats the idea

Basically, you need to tell angular that what ever link is being used, to trust it and that you know what it is.

EDIT: reread your original post and see you already have that.

Can you put together a codepen to show what you have?

So, in the end I should use


in the html and this method should be something like

$scope.validUrl = function() { return $sce.trustAsResourceUrl(videoUrl); }

So now it is working :smile: