在 Angular 我将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用于数组?
最佳答案
自己找出来
读完这个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'