BASE64成像角2

编程入门 行业动态 更新时间:2024-10-22 11:39:55
本文介绍了BASE64成像角2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试从角度为2的远程服务器显示图像。

I'm trying to show an image get from a remote server with angular 2.

在我的组件中,我有一个对象是university_info对象,是我的模特。

In my component I have an object that is an "university_info" object that is my model.

export class myClass { university_info : university_info; } myFunction() { this.university_info = new university_info(responseFromServer[image]) } export class university_info { imageBase64 : string constructor(image : string) { this.imageBase64 = image } }

一切正常。我得到base64图像,但当我尝试以这种方式在HTML中显示它时:

All is working fine. I get base64 image but when I try to show it in HTML in this way :

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

这就是我得到的:

推荐答案

您可以尝试使用 _sanitizer .bypassSecurityTrustUrl 告诉angular src 值是安全的。从角度看这个类:

You can try to use _sanitizer.bypassSecurityTrustUrl to tell angular src value is safe. Take a look at this class from angular:

class DomSanitizationService { sanitize(context: SecurityContext, value: any) : string bypassSecurityTrustHtml(value: string) : SafeHtml bypassSecurityTrustStyle(value: string) : SafeStyle bypassSecurityTrustScript(value: string) : SafeScript bypassSecurityTrustUrl(value: string) : SafeUrl bypassSecurityTrustResourceUrl(value: string) : SafeResourceUrl }

并且低安全html的示例:

and be low an example for safe html:

export class AppComponent { private _htmlProperty: string = '<input type="text" name="name">'; public get htmlProperty() : SafeHtml { return this._sanitizer.bypassSecurityTrustHtml(this._htmlProperty); } constructor(private _sanitizer: DomSanitizationService){} }

更多推荐

BASE64成像角2

本文发布于:2023-07-27 00:13:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219172.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!