4

这个想法是在角度端嵌入一个 pdf 文件,该文件由节点快递服务器以 blob 形式返回。 文件以blob形式返回

之后我得到图像并创建了一个 URL

const file = new Blob([this.data], { type: 'application/pdf' });
this.fileUrl = URL.createObjectURL(file);
this.protectedUrl = this.sanitizer.bypassSecurityTrustUrl(this.fileUrl);

然后在我在 html 中使用它之后

<object ng-show="content" data="{{protectedUrl}}" type="application/pdf" style="width: 100%; height: 400px;"></object>

然后即使在使用消毒剂 angular 后返回清洁 url 问题

4

2 回答 2

4

现在可以通过将数据更改为 attr.data

<object  [attr.data]="protectedUrl" type="application/pdf" style="width: 100%; height: 400px;"></object>

于 2019-04-29T07:11:16.900 回答
1

我对图像有类似的问题,解决方案如下:

<img *ngIf="protectedUrl" [src]="protectedUrl" />

PS 只要确保数据在绑定前准备好即可。

于 2019-04-29T07:14:59.907 回答