Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safe value must use [property]=binding after bypass security with DomSanitizer

<!--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);  } 

but the output which the mass_timings is displaying is including the text:-

Safe value must use [property]=binding

at the beginning

How to remove this string.

like image 284
manish kumar Avatar asked Jul 27 '17 12:07

manish kumar


1 Answers

As the error message says, the sanitized HTML needs to be added using property binding:

<p [innerHTML]="massTimingsHtml"></p> 
constructor(private domSanitizer:DomSanitizer) {   this.massTimingsHtml = this.getInnerHTMLValue(); } getInnerHTMLValue(){   return this.domSanitizer.bypassSecurityTrustHtml(this.parishDetail.mass_timings); } 

StackBlitz example (based on Swapnil Patwa's Plunker - see comments below)

like image 161
Günter Zöchbauer Avatar answered Sep 22 '22 10:09

Günter Zöchbauer