Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show two continuous spaces in Angular?

Tags:

UPDATE: Both ways from Chris and Mark work.

I am using Angular 2. I try to show two continuous spaces between a and bin 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?

like image 709
Hongbo Miao Avatar asked Feb 06 '16 22:02

Hongbo Miao


People also ask

What is &nbsp in angular?

You can use the ascii code for &nbsp in a string. Alt-255. This will correctly render as an &nbsp. 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.

Does HTML support multiple sequential blank spaces?

Hello. Hello. Hello. This is perfectly fine, as if you need multiple spaces of pre-formatted text you can just use the <pre> tag.

How do I add spaces to a string interpolation?

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.

What happens when a browser encounter multiple character space?

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.


1 Answers

Bind to DOM property innerHTML instead of DOM property textContent (which is what {{}} binds to):

<span [innerHTML]="text"></span>  text = "a&nbsp;&nbsp;b"; 
like image 119
Mark Rajcok Avatar answered Sep 25 '22 03:09

Mark Rajcok