资源 URL 上下文中使用的不安全值角度错误

Jig*_*try 4 iframe typescript angular

大家好,我想展示一个动态的 pdf。起初它向我展示了 CORS 错误。我使用 DOM Sanitizer 解决了这个问题。现在它向我显示不安全的 url 任何帮助表示赞赏。

HTML代码:

  <iframe src="{{Url}}"></iframe>
Run Code Online (Sandbox Code Playgroud)

TS Code:这里pdfSrc存放的是动态生成的pdf路径;

 this.pdfSrc = 'http://192.168.1.183/' + this.pdfPath;
 this.Url = this.sanitizer.bypassSecurityTrustUrl(this.pdfSrc);
Run Code Online (Sandbox Code Playgroud)

Jig*_*try 13

终于得到了解决方案,只是更改了 HTML 部分和 TS 部分如下

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

constructor(private sanitizer:DomSanitizer){}

this.Url = this.sanitizer.bypassSecurityTrustResourceUrl(this.pdfSrc);
Run Code Online (Sandbox Code Playgroud)

  • IM 收到这样的错误错误错误:NG0904:资源 URL 上下文中使用的不安全值(请参阅 https://g.co/ng/security#xss) (2认同)