我想以角度显示B64图像字符串。当我放置静态图像字符串时,它会显示,但是当图像是动态时,它会显示一些问题 下面是我的component.ts代码
this.Socket_io = socketIo('http://192.168.0.109:3011');
this.Socket_io.on('echo', (obj) => {
var a = JSON.parse(obj)
this.img = a.image_path;
this.image_path = this.sanitizer.bypassSecurityTrustResourceUrl('data:image/jpg;base64,'
+ this.img);
下面是我的html
<img [src]="image_path">
答案 0 :(得分:1)
尝试这样
<img [src]="image_path">
这是stackblitz https://stackblitz.com/edit/angular-view-image?file=src/app/app.component.html
答案 1 :(得分:1)
尝试一下:
Wa
答案 2 :(得分:0)
You can try this
import { DomSanitizer } from '@angular/platform-browser'; export abstract class AppComponentBase { sanitizer: DomSanitizer; } constructor(injector: Injector) { this.sanitizer = injector.get(DomSanitizer); } sanitize(image_path: string) { return this.sanitizer.bypassSecurityTrustUrl(image_path); }