Francisc Francisc - 20 days ago 5
AngularJS Question

$sce.trustAsResourceUrl() globally

How can I do something like this:

$sce.trustAsResourceUrl('URL_HERE');


Globally, like in the main app's
config()
or
run()
functions so that any iFrames, img src etc that have
URL_HERE
will work?

Docs are rather poor at explaining this.

Answer

I just read your comment from the previous answer. Not sure if you found a solution yet. Seems you are looking for a whitelist type of thing. I recently found this out that there's a whitelist function for $sce.

Taken from the AngularJS docs for $sceDelegateProvider:

angular.module('myApp', []).config(function($sceDelegateProvider) {
 $sceDelegateProvider.resourceUrlWhitelist([
   // Allow same origin resource loads.
   'self',
   // Allow loading from our assets domain.  Notice the difference between * and **.
   'http://srv*.assets.example.com/**']);
 })

With this you can do string interpolation in iframes like this:

<iframe ng-src="{{ 'http://srv1.assets.example.com/' + url_asset }}"></iframe>