尝试解决ng-src信任问题
angular.module('App', []);
function Ctrl($scope, $sce) {
// Construct a dummy blob Url
var canvas = document.createElement("canvas");
canvas.width = 100;
canvas.height = 100;
var ctx = canvas.getContext("2d");
ctx.fillStyle="#FF0000";
ctx.fillRect(0,0,100,100);
canvas.toBlob(function(blob){
$scope.src = $sce.trustAsResourceUrl(URL.createObjectURL(blob));
// works...
var img = document.createElement("img");
img.src = $scope.src;
document.body.appendChild(img);
});
}
答案 0 :(得分:2)
自己找到答案
app.config( ['$compileProvider', function($compileProvider){
$compileProvider.imgSrcSanitizationWhitelist(/^\s*(blob):/);
}]);