在angular2中显示嵌入式图像 [英] displaying an embedded image in angular2

查看:62
本文介绍了在angular2中显示嵌入式图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用angular2开发一个项目,该项目涉及直接从数据库中加载图像(base64编码).在angular1中,可以按以下方式简单地加载它:

I'm working on a project in angular2, which involves loading an image from a database directly (base64 encoded). In angular1, one could simply load it as follows:

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

其中entry.img是原始图像数据.但是,我不知道如何在angular2中执行此操作.我已经尝试过

where entry.img is the raw image data. However, I have no idea how to do this in angular2. I've tried

<img [src]="data:image/jpg;base64,{{entry.img}}" />

但这是行不通的,因为角度仍然尝试从URL加载图像.

but that doesn't work, as angular still tries to load the image from a URL.

推荐答案

也许您可以尝试以下方法:

Perhaps you could try this:

<img [src]="'data:image/jpg;base64,'+entry.img" />

假定entry是组件的属性,并且包含img属性.

assuming that entry is a property of the component and contains an img attribute.

这篇关于在angular2中显示嵌入式图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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