标签:cto const csdn san browser pass html inner port
1.导入模块
import { DomSanitizer } from ‘@angular/platform-browser‘;
2.在构造函数添加
constructor(private sanitizer: DomSanitizer) {
}
3.页面上使用方法
3.1使用变量
ts中:
assembleHTML =this.sanitizer.bypassSecurityTrustHtml(‘<p style="color:red;">测试加载html</p>’
html中:
<div [innerHTML]="assembleHTML"></div>
3.2使用方法
ts中:
assembleHTML(){ return this.sanitizer.bypassSecurityTrustHtml(‘<p style="color:red;">测试加载html</p>’); }
html中:
<div [innerHTML]="assembleHTML()"></div>
参:http://blog.csdn.net/u010730897/article/details/53609173
http://www.cnblogs.com/cjxhd/p/6607108.html
标签:cto const csdn san browser pass html inner port
原文地址:http://www.cnblogs.com/xindejiyi/p/6874374.html