Ama*_*noy 5 ngsanitize angular
我正在尝试动态地在 angular2 中的标签中加载 pdf 文档,当我尝试更改 URL 时,会抛出错误
SafeResourceUrlImplchangingThisBreaksApplicationSecurity:“localhost:8002/pdf.pdf”原型:SafeValueImpl构造函数:SafeResourceUrlImpl()getTypeName:()原型:对象
本地主机:8002/pdf.pdf 无法加载资源:net::ERR_UNKNOWN_URL_SCHEME
这是我设置 URL 的方法,当我需要显示组件时会调用此方法
public show(): void {
this.visible = true;
this.visibleAnimate = true;
console.log(this.src)
this.DocURL = this.sanitizer.bypassSecurityTrustResourceUrl(this.src);
console.log(this.DocURL);
}
constructor(private sanitizer: DomSanitizer) {
this.visible = false;
this.visibleAnimate = false;
this.DocURL = this.sanitizer.bypassSecurityTrustResourceUrl(window.location.host + "/pdf.pdf");
}
Run Code Online (Sandbox Code Playgroud)
HTML 部分如下
<div style=" height:650;width:870">
<object width="870" height="650" type="application/pdf" [data]="DocURL" id="doc" #doc>
<p>Not able to display the document</p>
</object>
<div style="display:none">
<iframe id="fred" #fred style="border:1px solid #666CCC" title="PDF in an i-Frame" [src]="DocURL" frameborder="1" scrolling="auto" height="1100" width="850" ></iframe>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我提供的 URL 将是动态的
您的 URL 没有协议。请尝试以下操作:
this.DocURL = this.sanitizer.bypassSecurityTrustResourceUrl(window.location.protocol + '//' + window.location.host + "/pdf.pdf");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16520 次 |
| 最近记录: |