【发布时间】:2019-06-27 06:27:51
【问题描述】:
我遇到了一个与 Angular 6 相关的问题,以及显示以 base64 格式编码的图像。任何想法为什么下面显示的代码不显示图像?
html:
<tr *ngFor="let row of this.UploaderService.tableImageRecognition.dataRows">
<img src="{{this.hello}}" />
ts:
this.hello = "data:image/png;base64, /9j/4AAQSkZJRgABAQAAA..."
虽然下面显示的代码可以正常工作并显示图片?
html:
<tr *ngFor="let row of this.UploaderService.tableImageRecognition.dataRows">
<!--<img src="data:image/png;base64, /9j/4AAQSkZJRgABAQAAA..."/>
this.hello 在构造函数中分配只是为了测试目的。我以这种方式创建它this.hello = 'data:image/png;base64, ' + this.UploaderService.imageRecognitionRowsData[0].toString() 我的主要目标是在这个循环<tr *ngFor="let row of this.UploaderService.tableImageRecognition.dataRows"> 中显示imageRecognitionRowsData。因此,对于第一次迭代,我将显示图像imageRecognitionRowsData[0],然后在下一次迭代中显示图像imageRecognitionRowsData[1] 等。this.UploaderService.tableImageRecognition.dataRows 的长度始终与this.UploaderService.imageRecognitionRowsData 相同当我添加<p>{{this.hello}}</p> 时,我在html 中得到相同的字符串。
我不知道出了什么问题。我也尝试了this.hello2 = this.sanitizer.bypassSecurityTrustResourceUrl(this.hello);、this.hello2 = this.sanitizer.bypassSecurityTrustUrl(this.hello);、<img [src]="this.hello" /> 等,但没有任何效果。任何想法如何解决这个问题?
【问题讨论】:
标签: html angular typescript base64 angular6