本文介绍了$ sce.trustAsResourceUrl()全球的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何做这样的事情:
$ sce.trustAsResourceUrl('URL_HERE');

How can I do something like this:$sce.trustAsResourceUrl('URL_HERE');

在全球范围内,如在主应用程序的配置()的run()功能,使任何iFrame中,IMG SRC等有 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.

推荐答案

我刚才读从previous回答您的评论。不知道如果你找到一个解决办法。看来你正在寻找一个白名单类型的东西。最近我发现了这一点,有对$ SCE白名单功能。

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.

从角文档措施:

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>

这篇关于$ sce.trustAsResourceUrl()全球的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 16:44