UPDATE: Both ways from Chris and Mark work.
I am using Angular 2. I try to show two continuous spaces between a
and b
in the page. I've tried all of these, but none of them works:
{{text}} text = "a\00a0\00a0b"; text = `a\00a0\00a0b`; text = "a b"; text = `a b`; text = "a b"; text = `a b`;
How can I make it work?
You can use the ascii code for   in a string. Alt-255. This will correctly render as an  . This was not the question how to insert non breaking space character in AngularJS but how to add html entities like < , > or it's obvious that you can insert any character into text.
Hello. Hello. Hello. This is perfectly fine, as if you need multiple spaces of pre-formatted text you can just use the <pre> tag.
You can use string interpolation by using template literals; replace the quotes with backticks(`)(https://www.computerhope.com/jargon/b/backquot.htm). Hope this helped you on your coding journey! I am not sure why they are teaching this method, but you can just add a space between the quotation marks.
Multiple spaces will be displayed, however, when text is tagged as preformatted text ( <pre> ). A series of <p> (paragraph) tags with no intervening text is interpreted as redundant by all browsers and will display as though it were only a single <p> tag.
Bind to DOM property innerHTML
instead of DOM property textContent
(which is what {{}}
binds to):
<span [innerHTML]="text"></span> text = "a b";
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