Rk *_*iri 3 css whitespace linefeed angularjs angular-filters
我有一个包含换行符/ n的字符串。尝试显示
字符串。而不是将/ n作为新行,而是将“ / n”显示为文本。
   $scope.myOutput = " Hello /n"
    {{ myOutput | textFormat }}
必需->您好(在html页上)
尝试过:
 app.filter('textFormat', function() {
    return function(x) {
      return x.replace(/\\n/g, '<br/>');
   }
尝试过CSS样式,例如空白:pre;
小智 12
在 Angular 中,您可以通过输入以下内容轻松将文本转换为原始格式:
成分:
this.myText = 'This is line one\nThis is line 2\nAnd here is 3'
html:
<div [innerText]='myText'></div>
它不会替代它,但是您可以使用CSS属性white-space: pre-line;在浏览器中呈现\ n:https :
 //developer.mozilla.org/zh-CN/docs/Web/CSS/white-space
div {
  white-space: pre-line;
}<div>Foo
   Bar
       Baz     Foo
     Bar
 
     
  Baz
</div>| 归档时间: | 
 | 
| 查看次数: | 6527 次 | 
| 最近记录: |