Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 507
Jignesh Mistry Avatar asked Dec 10 '22 06:12

Jignesh Mistry


1 Answers

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);
like image 56
Jignesh Mistry Avatar answered Mar 01 '23 23:03

Jignesh Mistry