AngularJS - 将字节数组内容显示为图像 [英] AngularJS - Show byte array content as image

查看:26
本文介绍了AngularJS - 将字节数组内容显示为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的数据库中搜索作为字节数组的图像.我想使用标记图像将此内容显示为文件,但在这里不起作用.

I'm searching into my database a image as a byte array. I want to show this content as file using the markup image, but it doesn't work here.

// Controller which get my image and put into $scope.
function MyController($scope, $http, $location) {  

    var url = '/json/FindImage?id=1';  
    $http.get(url).success(function(result) {  
        $scope.image = result.Image;  
    }  
}  

// HTML
<!-- It doesn't work -->  
<img src="{{image}}" />  
<!-- It doesn't work also -->  
<img ng-src="{{image}}" />  

有什么想法吗?谢谢大家!

Any idea? Thank you all!

推荐答案

使用ng-src格式如下

<img ng-src="data:image/JPEG;base64,{{image}}">

不要忘记为 data 添加一个消毒过滤器,以免被 angular 标记为 unsafe:

Don't forget to add a sanitization filter for data to not be marked as unsafe by angular:

$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|file|ftp|blob):|data:image\//);

这篇关于AngularJS - 将字节数组内容显示为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆