Videogular Angular 视频播放器喜欢在这样的对象中引用视频:
{
preload: "auto",
sources: [
{
src: $sce.trustAsResourceUrl("http://static.videogular.com/assets/videos/videogular.mp4"),
type: "video/mp4"
}
],
theme: "bower_components/videogular-themes-default/videogular.css"
}
$sce.trustAsResourceUrl
运行 URLng-sanitize
以防止恶意代码。
在我的控制器中,我在将视频上传到 Firebase 存储后制作了这个对象,该存储返回一个snapshot
对象:
var videoObject = {
preload: "auto",
sources: [
{
src: "$sce.trustAsResourceUrl(" + $scope.snapshot.downloadURL + ")",
type: "video/" + $scope.mediaFormat
},
],
theme: {
url: "http://www.videogular.com/styles/themes/default/latest/videogular.css"
}
};
结果是:
{
preload: "auto",
sources: [
{
src: "$sce.trustAsResourceUrl(http://static.videogular.com/assets/videos/videogular.mp4)",
type: "video/mp4"
}
],
theme: "bower_components/videogular-themes-default/videogular.css"
}
这不起作用,因为src
键的值是字符串,而我希望 a$sce.trustAsResourceUrl
不是字符串。
如果我这样制作对象:
var videoObject = {
preload: "auto",
sources: [
{src: $sce.trustAsResourceUrl +'("' + $scope.snapshot.downloadURL + '")', type: "video/" + $scope.mediaFormat}
],
theme: {
url: "http://www.videogular.com/styles/themes/default/latest/videogular.css"
}
};
然后我得到:
{
preload: "auto",
sources: [
{
src: "function (b){return g(a,b)}(\"http://static.videogular.com/assets/videos/videogular.mp4)",
type: "video/mp4"
}
],
theme: "bower_components/videogular-themes-default/videogular.css"
}
根据Mozilla的说法,“JavaScript 对象是键和值之间的映射。键是字符串(或符号),值可以是任何东西。” 如果值可以是任何东西,我如何制作一个部分是字符串而部分不是字符串的值?什么叫“部分是字符串,部分不是字符串”?字面意思?