Angular$sce阻止了我的音频src,尝试了$se.trustAsResourceUrl,但仍然出现错误



在angular中,我将awsomeThing.name设置为base64数据

我想把它读进去。

我试过了:

'use strict'
angular.module 'papaApp'
.config [
  "$compileProvider"
  ($compileProvider) ->
    $compileProvider.aHrefSanitizationWhitelist /^s*(https?|ftp|mailto|data):/
]
.controller 'MainCtrl', ['$scope', '$http', 'socket', '$sce', ($scope, $http, socket, $sce) ->
  $scope.awesomeThings = []
  $http.get('/api/things').success (awesomeThings) ->
    $scope.awesomeThings = awesomeThings
    socket.syncUpdates 'thing', $scope.awesomeThings
    for awesomeThing in $scope.awesomeThings
      $sce.trustAsResourceUrl awesomeThing.name
  $scope.addThing = ->
    return if $scope.newThing is ''
    $http.post '/api/things',
      name: $scope.newThing
    $scope.newThing = ''
  $scope.deleteThing = (thing) ->
    $http.delete '/api/things/' + thing._id
  $scope.$on '$destroy', ->
    socket.unsyncUpdates 'thing'
]

但仍然得到错误:

Error: [$sce:insecurl] Blocked loading resource from url not allowed by $sceDelegate policy.  URL: data:audio/mp3;base64,//sQxAADwAABpAAAACAAADSAAAAE8cGnkAH+AOE/hcIGJPyWA8gso…VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVQ==

我应该如何对数组使用$sce.trustAsResourceUrl?

自行查找

在阅读了这篇Angular JS Handling Ng Repeated HTML5 Video&SCE-

angular.module 'papaApp'
.config ($sceDelegateProvider) ->
  $sceDelegateProvider.resourceUrlWhitelist [
    # Allow same origin resource loads.
    "self"
    # Allow loading from our assets domain.  Notice the difference between * and **.
    "data:**"
  ]
  return
.controller 'MainCtrl', ($scope, $http, socket) ->
  $scope.awesomeThings = []
  $http.get('/api/things').success (awesomeThings) ->
    $scope.awesomeThings = awesomeThings
    socket.syncUpdates 'thing', $scope.awesomeThings
  $scope.addThing = ->
    return if $scope.newThing is ''
    $http.post '/api/things',
      name: $scope.newThing
    $scope.newThing = ''
  $scope.deleteThing = (thing) ->
    $http.delete '/api/things/' + thing._id
  $scope.$on '$destroy', ->
    socket.unsyncUpdates 'thing'

相关内容

  • 没有找到相关文章

最新更新