[英]Angular JS Handling Ng-Repeated HTML5 Video & $SCE
JSfiddle here: http://jsfiddle.net/TegFf/73/ JS在这里: http : //jsfiddle.net/TegFf/73/
From this answer , I understand Angular 1.2 ships with Strict Contextual Escaping (SCE) enabled. 从这个答案 ,我了解Angular 1.2附带启用严格上下文转义(SCE)。 This affects the parser of expressions using
ng-src
with an HTML5 video. 这会影响使用
ng-src
和HTML5视频的表达式解析器。 I understand that if I wrap $sce.trustAsResourceUrl(videoURL)
around each of my video sources, then Angular will play them as normal. 我知道如果我在我的每个视频源周围包装
$sce.trustAsResourceUrl(videoURL)
,那么Angular将正常播放它们。 However, I am getting a list of video sources back from an API. 但是,我从API获取了一个视频源列表。 It is expensive for me to loop over item in the array, assign each source as a
$sce.trustAsResourceUrl
, and then loop over that new array in my view. 循环遍历数组中的项目,将每个源分配为
$sce.trustAsResourceUrl
,然后在我的视图中循环遍历该新数组,这对我来说很昂贵。
What is the most efficient way of assigning all my video sources as trusted without having to loop over all of them? 将所有视频源分配为受信任的最有效方法是什么,而不必遍历所有视频源? Can I assign all video sources to be
$sce
trusted beforehand? 我可以事先将所有视频源分配为
$sce
信任吗?
It looks like what you want is to whitelist the domain these videos will be served from. 看起来你想要的是将这些视频提供的域列入白名单。 You can do this using $sceDelegateProvider
你可以使用$ sceDelegateProvider来做到这一点
All you need to do is add a bit of config as follows: 您需要做的就是添加一些配置,如下所示:
app.config(function($sceDelegateProvider) {
$sceDelegateProvider.resourceUrlWhitelist([
// Allow same origin resource loads.
'self',
// Allow loading from our assets domain. Notice the difference between * and **.
'http://media.w3.org/**']);
});
I've updated your fiddle with a working demo: http://jsfiddle.net/spikeheap/ACJ77/1/ 我用工作演示更新了你的小提琴: http : //jsfiddle.net/spikeheap/ACJ77/1/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.