角JS处理伍重复的HTML5视频和放大器; $ SCE [英] Angular JS Handling Ng-Repeated HTML5 Video & $SCE

查看:170
本文介绍了角JS处理伍重复的HTML5视频和放大器; $ SCE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里的jsfiddle: http://jsfiddle.net/TegFf/73/

JSfiddle here: http://jsfiddle.net/TegFf/73/

从这个<一个href=\"http://stackoverflow.com/questions/19372300/angular-js-dynamic-ng-src-not-working-in-1-2-0-rc-2\">answer,我理解角1.2附带严格的语境逃逸(SCE)启用。这会影响使用前pressions NG-SRC 与HTML5视频的解析器。我明白,如果我换 $ sce.trustAsResourceUrl(videoURL)围绕我的每一个视频源,然后将角发挥他们正常。但是,我得到的视频信号源列表,从API回来。它是昂贵的,我遍历项目在数组中,每个源分配为 $ sce.trustAsResourceUrl ,然后循环遍历我认为,新的数组。

From this answer, I understand Angular 1.2 ships with Strict Contextual Escaping (SCE) enabled. This affects the parser of expressions using ng-src with an HTML5 video. I understand that if I wrap $sce.trustAsResourceUrl(videoURL) around each of my video sources, then Angular will play them as normal. However, I am getting a list of video sources back from an 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 事前是否可信?

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?

推荐答案

看起来你想要的是白名单,这些影片将要服务的领域。您可以通过做到这一点 $ sceDelegateProvider

It looks like what you want is to whitelist the domain these videos will be served from. You can do this using $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/**']);
});

我已经有工作演示更新您的提琴: http://jsfiddle.net/spikeheap/ ACJ77 / 1 /

这篇关于角JS处理伍重复的HTML5视频和放大器; $ SCE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆