小编Ara*_*nth的帖子

$ sce:itype尝试信任需要字符串的内容中的非字符串值:Context:resourceUrl

我想播放存储在我的sails服务器中的歌曲.路径是http://localhost:4000/images/123.mp3.

在前端,我使用ng-repeat列出来自服务器的歌曲.

 <div ng-repeat="tones in ringTones track by $index">
      <div>
        <i ng-show="playpause" class="fa fa-play-circle"   ng-click="playpause=!playpause" onclick="plays(event);"><audio id="audio_{{$index}}" ng-src="tones.tonePath"></audio></i> 
        <i ng-show="!playpause" class="fa fa-pause"   ng-click="playpause=!playpause" onclick="stop(event);"></i></div>

</div>
Run Code Online (Sandbox Code Playgroud)

此音频源导致外部资源问题

<audio ng-src="tones.tonePath"></audio>
Run Code Online (Sandbox Code Playgroud)

在角度控制器中,我正在使用$ sce

$http.get("http://localhost:4000/songs/find").success(function(data){
        $rootScope.ringTones=data;
        $rootScope.ringTones.push($sce.trustAsResourceUrl(data[0]));
 }).error(function(data){
                    console.log('ERROR');
 });
Run Code Online (Sandbox Code Playgroud)

错误是:

Error: [$sce:itype] Attempted to trust a non-string value in a 
    content requiring a string: Context: resourceUrl
Run Code Online (Sandbox Code Playgroud)

没有使用导致的$ sce

Error: [$interpolate:interr] Can't interpolate: tones.tonePath
Error: [$sce:insecurl] Blocked loading resource from url not allowed by $sceDelegate policy.  URL
Run Code Online (Sandbox Code Playgroud)

这是我的服务器JSON

 [{
    "toneName": "2",
    "aboutTone": …
Run Code Online (Sandbox Code Playgroud)

angularjs angularjs-ng-repeat sails.js ngsanitize

5
推荐指数
1
解决办法
1万
查看次数