changesThisBreaksApplicationSecurity angular2 [英] changingThisBreaksApplicationSecurity angular2
问题描述
我试图动态地在angular2的标签中加载pdf文档,并且当我尝试更改URL时会抛出错误提示
I am trying to load a pdf document in an tag in angular2 Dynamically, and when I am trying to change the URL iths throwing an error saying
SafeResourceUrlImplchangingThisBreaksApplicationSecurity:"localhost:8002/pdf.pdf" 协议:SafeValueImplconstructor:SafeResourceUrlImpl()getTypeName:() proto :对象
SafeResourceUrlImplchangingThisBreaksApplicationSecurity: "localhost:8002/pdf.pdf"proto: SafeValueImplconstructor: SafeResourceUrlImpl()getTypeName: ()proto: Object
localhost:8002/pdf.pdf无法加载资源:网址:: ERR_UNKNOWN_URL_SCHEME
localhost:8002/pdf.pdf Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME
这是我设置网址的方式,当我需要显示组件时,将调用此方法
Here's how I am setting the URL, This method will be called when I need to show the component
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");
}
此处是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>
我提供的URL是动态的
The URL I am supplying will be dynamic
推荐答案
您的URL没有协议.请尝试以下操作:
Your URL does not have a protocol. Try the following:
this.DocURL = this.sanitizer.bypassSecurityTrustResourceUrl(window.location.protocol + '//' + window.location.host + "/pdf.pdf");
这篇关于changesThisBreaksApplicationSecurity angular2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!