Angular 11:我无法显示 pdf



我正在尝试将Base64中的字符串显示为PDF并在浏览器中下载,当我发送拥有它的变量时,它不会在浏览器中显示。

app.component.html->

<div class="modal-header">
<h3 style="font-size: 1.2em; color: #838181" class="modal-title" id="modal-title">
{{ terminosCondicionesModalSeguroVidaTitulo }}
</h3>
<button type="button" class="close" aria-describedby="modal-title" (click)="close()">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">

<iframe width='100%' height='100%' src=''>{{SeguroVida}}</iframe>

</div>
<div class="modal-footer">
<input type="submit" class="btnGenericGreen next" (click)="Aprobar()"
value="{{ terminosCondicionesModalSeguroVidaBoton }}" />
</div>

app.component.ts->

llenadoParametros() {
console.log(this.paramArray.find((x) => x.codigo === DocumentsAcceptation.SeguroVida) ? .valorAlfa || '');
this.SeguroVida = this.paramArray.find(
(x) => x.codigo === DocumentsAcceptation.SeguroVida
) ? .valorAlfa || '';
this.SeguroVida = this.sanitizer.bypassSecurityTrustUrl('data:application/pdf;base64,' + this.paramArray.find((x) => x.codigo === DocumentsAcceptation.SeguroVida) ? .valorAlfa || '');
}

我仍然不知道为什么它没有在浏览器中显示。我做错了什么?

您必须将src设置为iframe。

<iframe width='100%' height='100%' [src]='SeguroVida'></iframe>

最新更新