how with angular2 rc.6 disable sanitize on embed h

2020-02-14 09:36发布

问题:

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

Template:

<embed [src]="pdfUrl" width="500" height="100%" type='application/pdf'>

Class:

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

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

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

回答1:

I quess it should be:

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

and use it like:

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

See Plunkr

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

For embed tag you can reinject embed tag via outerHTML:

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

See plunker for this case



回答2:

first thanks you but I don't understand I have exactly the same and see the result

my embed is not display... i don't have css to hide it :

I think it is because I don't reinject embed tag? When I open sidenav my embed already exist I just change the src url and it doesn't realod content, is there solution ?



回答3:

But here you can see with FIREFOX it works fine :



标签: angular