Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何使用angular2 rc.6在显示pdf的embed html标签上禁用sanitize大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我真的不明白我在做错了什么:

模板:

<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>但不会抛出错误.

我在pdfURL和bypassSecurityTrustresourceUrl()上使用SafeUrl类型尝试了它.
<嵌入>标签收到正确的URL但没有显示任何内容.

解决方法

我认为它应该是:

this.pdfUrl = this.domSanitizer.bypassSecurityTrustresourceUrl('url')

并使用它像:

<iframe [src]="pdfUrl" width="500" height="600" type='application/pdf'></iframe>

Plunkr

更新(Chrome中的嵌入代码存在错误)

对于embed标记,您可以通过outerHTML重新注入embed标记

this.renderer.setElementProperty(el,'outerHTML',el.outerHTML)

对于这种情况,请参见plunker

大佬总结

以上是大佬教程为你收集整理的如何使用angular2 rc.6在显示pdf的embed html标签上禁用sanitize全部内容,希望文章能够帮你解决如何使用angular2 rc.6在显示pdf的embed html标签上禁用sanitize所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。