Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

angular - how with angular2 rc.6 disable sanitize on embed html tag which display pdf

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...