出于某种原因,我的某些图像被添加了 '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/