在角度我将awesomeThing.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作为数组?
答案 0 :(得分:1)
自己找出
阅读此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'