从后端检索图像路径并在 angular html 模板中显示图像抛出不安全错误
Retrieve image path from back end and display the image in angular html template throws unsafe error
大家好我的代码我正在从后端检索图像路径,我在 src 属性中设置了该路径。[src]="图像路径"我认为这会显示图像,但在浏览器控制台中显示它显示警告:清理不安全 URL 值:
和错误无法加载资源:net::ERR_UNKNOWN_URL_SCHEME 不安全:
我在前端使用 angular,在后端使用 spring。
我的HTML如下
HTML
将以下内容添加到您的组件中:
import {DomSanitizationService} from '@angular/platform-browser';
constructor(private _DomSanitizationService: DomSanitizationService) {}
以及您的模板中的以下内容:
<img [src]="_DomSanitizationService.bypassSecurityTrustUrl(imgSrcProperty)"/>
其中 imgSrcProperty
是有问题的图像 base64 编码。
大家好我的代码我正在从后端检索图像路径,我在 src 属性中设置了该路径。[src]="图像路径"我认为这会显示图像,但在浏览器控制台中显示它显示警告:清理不安全 URL 值: 和错误无法加载资源:net::ERR_UNKNOWN_URL_SCHEME 不安全: 我在前端使用 angular,在后端使用 spring。 我的HTML如下 HTML
将以下内容添加到您的组件中:
import {DomSanitizationService} from '@angular/platform-browser';
constructor(private _DomSanitizationService: DomSanitizationService) {}
以及您的模板中的以下内容:
<img [src]="_DomSanitizationService.bypassSecurityTrustUrl(imgSrcProperty)"/>
其中 imgSrcProperty
是有问题的图像 base64 编码。