Angularjs

Can't Interpolate Error With Iframe And Ng-src In AngularJS 1.x

Posted by Weston Ganger on November 17, 2016

If you have ever tried to use an iframe, video or media element tag with a external site as source you have probably seen the Can't interpolate error. Heres two simple methods to get this working for you.

Method 1: Simple & Hackish


<iframe ng-src='{{ trustSrc(mainVideoUrl + video.filename) }}'>
</iframe>

Method 2: Proper Way


.config(function($sceDelegateProvider){
  $sceDelegateProvider.resourceUrlWhitelist([
    'self',
    "http://www.youtube.com/embed/**"
  ]);
})

Now you can use any url from youtube.com/embed/* or this domain.


<!-- Assuming mainVideoUrl == 'http://www.youtube.com/embed/'-->
<iframe ng-src='{{ mainVideoUrl + video.filename }}'>
</iframe>


Related External Links:


Posted in Angular and Tagged with iframe angularjs 


Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts