I have a normal binding like this {{foo}}
and it displays foo's value as text in the HTML. The text that comes from the server is "R&D"
. I need this to display as "R&D". Any help?
When you want to insert a special character, select Insert > HTML > Special Characters. From there are you presented with a few of the most common, or you can choose “Other” to view all the characters available. Simply select the character you would like to insert and the code is inserted for you.
Special characters are specific pieces of HTML code designed to display characters that are used in the HTML code or to include characters that are not found on the keyboard in the text the viewer sees.
{{}}
is for string binding.
Use attribute binding to innerHTML
instead to get these characters displayed correctly.
<div [innerHTML]="foo">
See https://stackoverflow.com/a/41089093/217408 for more details.
For a little more fun and flexibility, you can create a pipe that parses HTML entities:
@Pipe({name: "decodeHtmlString"}) export class DecodeHtmlString implements PipeTransform { transform(value: string) { const tempElement = document.createElement("div") tempElement.innerHTML = value return tempElement.innerText } } {{foo | decodeHtmlString}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With