I'm using the following string
"Today's product of the day is {{product_code}} !"
This string above, I've sanitized and bypassed security trusted HTML
this.DomSanitizer.bypassSecurityTrustHtml(str)
and put in my template using [innerHTML]
.
However this string also contains interpolation {{product_code}}
that should have been evaluated and rendered with its actual value, such that the output must be
"Today's product of the day is XYZ-52-TV !"
However, that does not happen, instead the string gets rendered as is with the interpolation's double curly braces and the variable name.
How can I fix this?
UPDATE
component template:
<span [innerHTML]="trustHTML(str)"></span>
code for trustHTML()
:
trustHTML(t){
return this.DomSanitizer.bypassSecurityTrustHtml(t);
}
value of str
:
"Today's product of the day is {{trustHTML(product_code)}} !"
output using this value that appears is (not desired output):
Today's product of the day is {{trustHTML(product_code)}} !
I also tried value of str
:
"Today's product of the day is <span [innerHTML]="trustHTML(product_code)"></span> !"
"Today's product of the day is product_code !"