如何与angular2 rc.6禁用对显示pdf的嵌入html标签的清理 [英] how with angular2 rc.6 disable sanitize on embed html tag which display pdf

查看:86
本文介绍了如何与angular2 rc.6禁用对显示pdf的嵌入html标签的清理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的不明白我在做什么错:

I really don't understand what I'm doing wrong here:

模板:

<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>,但不会引发错误.

This does not actually load the <embed> but doesn't throw an error.

我在pdfURLbypassSecurityTrustResourceUrl()上使用SafeUrl类型尝试了它. <embed>标记收到正确的URL,但未显示任何内容.

I tried it using SafeUrl type on pdfURL and with bypassSecurityTrustResourceUrl(). The <embed> tag receives the right url but nothing is displayed.

推荐答案

我认为它应该是:

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

并像这样使用它:

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

请参见 Plunkr

See Plunkr

更新(Chrome中的embed标记存在错误)

Update(There is a bug with embed tag in Chrome)

对于embed标签,您可以通过outerHTML重新插入embed标签:

For embed tag you can reinject embed tag via outerHTML:

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

在这种情况下,请参见 朋克车

See plunker for this case

这篇关于如何与angular2 rc.6禁用对显示pdf的嵌入html标签的清理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆