如何使用angular2 rc.6在显示pdf的embed html标签上禁用sanitize

ebe*_*beg 3 angular

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

模板:

<embed [src]="pdfUrl" width="500" height="100%" type='application/pdf'>
Run Code Online (Sandbox Code Playgroud)

类:

pdfURL;
constructor(private domSanitizer : DomSanitizer) {}
ngOnInit() {
    this.pdfUrl = this.domSanitizer.bypassSecurityTrustUrl('http://example.com/pdf.pdf')
}
Run Code Online (Sandbox Code Playgroud)

这实际上不会加载<embed>但不会抛出错误.

我尝试使用SafeUrltype on pdfURL和with bypassSecurityTrustResourceUrl().该<embed>标签接收正确的URL,但不显示任何内容.

yur*_*zui 8

我认为它应该是:

this.pdfUrl = this.domSanitizer.bypassSecurityTrustResourceUrl('url')
Run Code Online (Sandbox Code Playgroud)

并使用它像:

<iframe [src]="pdfUrl" width="500" height="600" type='application/pdf'></iframe>
Run Code Online (Sandbox Code Playgroud)

Plunkr

更新(embedChrome中标记有错误)

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

this.renderer.setElementProperty(el, 'outerHTML', el.outerHTML)
Run Code Online (Sandbox Code Playgroud)

请参阅此案例的plunker