Angular在渲染视频和音频的url地址时报错

项目是一种答题小游戏,题目里面有文字、图片、视频和音频4种格式,我用的angular框架,但是在渲染视频和音频时老是报错,用了$sce还是不能解决,求助大神。
下面是html部分的代码

<div class="other">
    <img  ng-src="{{store.sub[index].attachment}}" class="image"/>
    <video width='100%' height="auto" class="video" controls="controls">
        <source ng-src="{{store.sub[index].attachment}}">
    </video>
    <audio class="audio" controls="controls">
        <source ng-src="{{store.sub[index].attachment}}">
    </audio></div>

js里面

.controller("timer",function($scope,$state,$sce){        var str=$scope.store.sub[index].attachment;
        $scope.store.sub[index].attachment=$sce.trustAsResourceUrl(str);
    })

https://img1.mukewang.com/5bab43ba000163d507380211.jpg

四季花海
浏览 690回答 1
1回答

元芳怎么了

.filter('trustAsResourceUrl', ['$sce', function($sce) {&nbsp; &nbsp; return function(val) {&nbsp; &nbsp; &nbsp; &nbsp; return $sce.trustAsResourceUrl(val);&nbsp; &nbsp; };}])<div class="other">&nbsp; &nbsp; &nbsp; &nbsp; <img&nbsp; ng-src="{{store.sub[index].attachment|trustAsResourceUrl}}" class="image"/>&nbsp; &nbsp; &nbsp; &nbsp; <video width='100%' height="auto" class="video" controls="controls">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <source ng-src="{{store.sub[index].attachment|trustAsResourceUrl}}">&nbsp; &nbsp; &nbsp; &nbsp; </video>&nbsp; &nbsp; &nbsp; &nbsp; <audio class="audio" controls="controls">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <source ng-src="{{store.sub[index].attachment|trustAsResourceUrl}}">&nbsp; &nbsp; &nbsp; &nbsp; </audio>&nbsp; &nbsp; </div>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript