<div [innerHTML]="html"></div>
当 html 包含 iframe 时不起作用。我试图用 做一些安全绕过this.sanitizer.bypassSecurityTrustResourceUrl(...
,但它仍然不起作用。
这是angular2 未正确注入的演示。
<div [innerHTML]="html"></div>
当 html 包含 iframe 时不起作用。我试图用 做一些安全绕过this.sanitizer.bypassSecurityTrustResourceUrl(...
,但它仍然不起作用。
这是angular2 未正确注入的演示。
您需要为此使用bypassSecurityTrustHtml
,并且需要html
像这样分配和使用经过消毒的
this.html = this.sanitizer.bypassSecurityTrustHtml(this.html);
DomSanitizationService 从 angular2 RC6 过时了
如果您使用的是 angular2 RC5,请使用这个-
DomSanitizationService
如果您要迁移到 angular2 RC6,请使用此-
DomSanitize
这是完整的示例
import {DomSanitizer} from '@angular/platform-browser';
然后添加结构
private sanitizer: DomSanitizer
并像这样在您的变量上应用消毒剂
let text = <iframe width="977" height="733" src="https://www.youtube.com/embed/C0DPdy98e4c" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
text = this.sanitizer.bypassSecurityTrustHtml(text);
return text;