AngularJS ng-src inside of iframe

You can use a filter instead:

HTML:

<iframe src="https://stackoverflow.com/questions/24163152/{{yourURL" trustAsResourceUrl}}"></iframe>

where ‘yourURL’ is the URL of the iframe and ‘trustAsResourceUrl’ is the filter and is defined as in some module(like eg. filters-module) as:

JS:

angular.module('filters-module', [])
.filter('trustAsResourceUrl', ['$sce', function($sce) {
    return function(val) {
        return $sce.trustAsResourceUrl(val);
    };
}])

And you can use this filter in all the iframes and other embedded items in your application.
This filter will take care of all the urls that you need to trust just by adding the filter.

Leave a Comment