绑定html内容
如果用正常的方法去绑定的话,可能会出再这种警告
<div [innerHTML]="Catcha" ></div>
--------------------------------------- WARNING: sanitizing HTML stripped some content (see http://g.co/ng/security#xss).
在网上找了一些,说要写指令对其进行转,好麻烦,从官网也找到一个种办法。
bypassSecurityTrustHtml 用这个来进行安装转换。
在返回的结果对内容,或内容字段进行转换,当然要使用 bypassSecurityTrustHtml 的话,还是要依赖注入 DomSanitizer 服务,
import { DomSanitizer } from '@angular/platform-browser';
export class myPage1{
constructor(private sanitizer: DomSanitizer) {
}
onInit():void{
this.Catcha = this.sanitizer.bypassSecurityTrustHtml('要进行转换的内容');
// 这里比如返回的一个html内容,或是其它如一张 svg 的图等,用上面代码转一下就可以了,就不会那那个错误了。
}
}