5

The idea is to embed a pdf file on angular side that is being returned by node express server in blob form. file is returned in the form of blob

After then i get the image and created a URL

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

And then after i use this in html

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

and then even after using the sanitizer angular is returning the cleaning url problem

Puneet Sharma
  • 246
  • 3
  • 14

2 Answers2

4

It's working now by changing data to attr.data

<object  [attr.data]="protectedUrl" type="application/pdf" style="width: 100%; height: 400px;"></object>
Puneet Sharma
  • 246
  • 3
  • 14
1

I had similar issues for images and the solution was the following:

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

P.S. Just make sure that the data is ready before binding.

Just Shadow
  • 10,860
  • 6
  • 57
  • 75