in angular2 html inject

2019-01-18 15:34发布

<div [innerHTML]="html"></div> isn't working when the html contains an Iframe. I've tried to do some security bypass with this.sanitizer.bypassSecurityTrustResourceUrl(..., but it still doesn't work.

Here's the demo with angular2 not injecting correctly.

1条回答
仙女界的扛把子
2楼-- · 2019-01-18 15:40

Working PLUNKER

You need to use bypassSecurityTrustHtml for that, and need to assign and use the sanitized html like this

this.html = this.sanitizer.bypassSecurityTrustHtml(this.html);
查看更多
登录 后发表回答