image - ionic 2 + Angular 2 : Images prepended with 'unsafe:' therefore not displaying even though they're fine

标签 image angular ionic2

出于某种原因,我的某些图像被添加了 'unsafe:' 前缀,这导致它们无法呈现。

问)为什么会发生这种情况,我该如何解决 - Angular 2 是否与白名单或 Ionic 2 不一致?

例如

<p><img src="unsafe:data:image/jpeg;base64,/9.....
<p><img src="data:image/jpeg;base64,/9.....

图片没有问题(看这里),看plunkr here

第二张图片是从 Ionic 2 渲染的,第一张图片我手动删除了前缀以显示它没问题。

最佳答案

对于遇到此问题的任何人,我已经使用以下方法“解决”了它:

类:

import {DomSanitizationService} from '@angular/platform-browser';

constructor(private _DomSanitizationService: DomSanitizationService) {}

模板:

<img [src]="_DomSanitizationService.bypassSecurityTrustUrl(imgSrcProperty)"/>

其中 imgSrcProperty 是有问题的 base64 编码图像。

我仍然认为这是一个错误!

关于image - ionic 2 + Angular 2 : Images prepended with 'unsafe:' therefore not displaying even though they're fine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38080654/

相关文章:

angular - 如何在 Reactive Forms 中发送 *NgFor 选项的值

javascript - Ionic 2 Angular 2 - 如何通过 Action Sheet 刷新当前页面的数据?

ionic2 - 使用提醒确认按钮打开 Google Play

angular - ionic 2 应用程序中的装饰器@page、@component 和@app 是什么意思?

ios - WatchKit 模糊的背景图像

html - 图像上的过渡淡入淡出不起作用

angular - “错误”,没有描述 Angular CLI

c++ - 在 OpenCV 中寻找轮廓?

android - 如何将图像文件从 URL 下载到 ByteArray?

html - 如何在 Angular Material 出现垫子错误之前正确对齐图像?