Jignesh Mistry
Jignesh Mistry

Reputation: 2479

unsafe value used in a resource URL context Angular Error

Hello Guys I want to show a dynamic pdf. At first it was showing me CORS error. I solved that using DOM Sanitizer. Now it is showing me unsafe url Any Help is appreciated.

HTML Code :

  <iframe src="{{Url}}"></iframe>

TS Code : Here pdfSrc stores the dynamic generated pdf path;

 this.pdfSrc = 'http://192.168.1.183/' + this.pdfPath;
 this.Url = this.sanitizer.bypassSecurityTrustUrl(this.pdfSrc);

Upvotes: 4

Views: 16512

Answers (1)

Jignesh Mistry
Jignesh Mistry

Reputation: 2479

Finally got the solution just changed the HTML Part & TS PART AS BELOW

<iframe [src]='Url' width="100%" height="1000px"></iframe>

constructor(private sanitizer:DomSanitizer){}

this.Url = this.sanitizer.bypassSecurityTrustResourceUrl(this.pdfSrc);

Upvotes: 15

Related Questions