How to show two continuous spaces in Angular?

UPDATE: both paths from Chris and Mark are working.

I am using Angular 2. I am trying to show two continuous spaces between a and b on the page. I tried all this, but none of them work:

 {{text}} text = "a\00a0\00a0b"; text = 'a\00a0\00a0b'; text = "a  b"; text = 'a  b'; text = "ab"; text = 'a b'; 

How can I make this work?

+11
html angular
source share
3 answers

Bind to the DOM property innerHTML instead of the DOM property textContent (to which {{}} is bound):

 <span [innerHTML]="text"></span> text = "a&nbsp;&nbsp;b"; 
+13
source share

I believe that you get this because of the nature of stripping HTML space.

Perhaps you can use the white-space: pre css property for any element that you render.

 function MyCtrl($scope) { $scope.text = 'a b'; } ... <p style="white-space: pre">{{text}}</p> 

I don’t know much about your application, but maybe that’s enough.

demonstration

+7
source share

use '&#160;' instead of '&nbsp;' in the template.

+2
source share

All Articles