我真的不明白我在这里做错了什么:
模板:
<embed [src]="pdfUrl" width="500" height="100%" type='application/pdf'>
类:
pdfURL;
constructor(private domSanitizer : DomSanitizer) {}
ngOnInit() {
this.pdfUrl = this.domSanitizer.bypassSecurityTrustUrl('http://example.com/pdf.pdf')
}
这实际上并没有加载 <embed>
但不会引发错误。
我尝试使用 SafeUrl
输入 pdfURL
和 bypassSecurityTrustResourceUrl()
.
<embed>
标记收到正确的 url,但未显示任何内容。
最佳答案
我猜应该是:
this.pdfUrl = this.domSanitizer.bypassSecurityTrustResourceUrl('url')
并像这样使用它:
<iframe [src]="pdfUrl" width="500" height="600" type='application/pdf'></iframe>
参见 Plunkr
更新(Chrome中的embed
标签有bug)
对于 embed
标签,您可以通过 outerHTML
重新注入(inject) embed 标签:
this.renderer.setElementProperty(el, 'outerHTML', el.outerHTML)
参见 plunker 对于这种情况
关于angular - angular2 rc.6 如何禁用显示 pdf 的嵌入 html 标签上的清理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39393431/