<!--HTML CODE-->
<p #mass_timings></p>
//Controller code
@ViewChild('mass_timings') mass_timings: ElementRef;
constructor(private domSanitizer:DomSanitizer)
getInnerHTMLValue(){
this.mass_timings.nativeElement.innerHTML =
this.domSanitizer.bypassSecurityTrustHtml(this.parishDetail.mass_timings);
}
但mass_timings显示的输出包括以下文本:
一开始
如何删除此字符串。
最佳答案
如错误消息所述,需要使用属性绑定(bind)添加经过清理的HTML:
<p [innerHTML]="massTimingsHtml"></p>
constructor(private domSanitizer:DomSanitizer) {
this.massTimingsHtml = this.getInnerHTMLValue();
}
getInnerHTMLValue(){
return this.domSanitizer.bypassSecurityTrustHtml(this.parishDetail.mass_timings);
}
StackBlitz example(基于Swapnil Patwa的Plunker-参见下面的评论)
关于javascript - 使用DomSanitizer绕过安全性后,安全值必须使用[property] = binding,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45351434/