1

I am trying to get a youtube video inserted into my website with AngularJS, but I keep getting the same error:

Error: $interpolate:interr Interpolation Error

Why do I get this error and how can I get rid of it? All I want is to insert the video...

App.js

var myApp = angular.module('myApp', [
    'duScroll', 'duParallax', 'angularFileUpload', 'ngRoute', 'ngSanitize'
]);

myApp.filter('youtube', ['$sce', function($sce) {
    return function(val) {
        var videoLink = val;
        var watch = val.indexOf("?v=") + 3;
        var playlist = val.indexOf('&') + 1;

        if (playlist > 0) {
            return $sce.getTrustedResourceUrl('//www.youtube.com/embed/' + val.substring(watch, playlist));
        } else {
            return $sce.getTrustedResourceUrl('//www.youtube.com/embed/' + val.substring(watch, videoLink.length));
        }
    };
}]);

index.jade

iframe(ng-if="story.media.video" src="{{ story.media.video | youtube }}" frameborder="0" allowfullscreen)

2 Answers 2

3

In this case it would seem simpler to whitelist the youtube embed path and get rid of the filter.

Also, you should also use ng-src instead of src for the iframe.

myApp.config(["$sceDelegateProvider", function($sceDelegateProvider) {
    $sceDelegateProvider.resourceUrlWhitelist([
        'self',
        "http://www.youtube.com/embed/**"
    ]);
}]);
Sign up to request clarification or add additional context in comments.

Comments

0

I solved with this Jquery basic:

src="http://www.youtube.com/embed/bSMInVPIE8o?autoplay=1"
$JQ('iframe').attr('src',src);

1 Comment

You should update your answer so that code is appropriately in either inline formatting or in code blocks (see meta.stackexchange.com/questions/22186/…)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.