将新行/n 转换为有角度的换行符 [英] convert new line /n to a line break in angular

查看:26
本文介绍了将新行/n 转换为有角度的换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含换行符/n 的字符串.试图显示

字符串.它没有将/n 作为新行,而是将 '/n' 显示为文本.

 $scope.myOutput = "你好/n"{{ 我的输出 |文本格式 }}

必需 -> 你好(在 html 页面上)

尝试过:

 app.filter('textFormat', function() {返回函数(x){return x.replace(/\\n/g, '<br/>');}

尝试过 css 样式,如 white-space: pre;

解决方案

这并不能代替它,但是可以使用 CSS 属性 white-space: pre-line; 来渲染\n在浏览器中:https://developer.mozilla.org/en-US/docs/Web/CSS/white-space

div {空白:前行;}

Foo酒吧巴兹富酒吧巴兹

I have a string which contain new line character /n. Trying to display

the string. Instead of taking the /n as new line, it displays '/n' as text.

   $scope.myOutput = " Hello /n"

    {{ myOutput | textFormat }}

Required -> Hello (on html page)

Tried :

 app.filter('textFormat', function() {
    return function(x) {
      return x.replace(/\\n/g, '<br/>');
   }

Tried css styles like white-space: pre;

解决方案

This does not replace it, but you can use the CSS attribute white-space: pre-line; to render the \n in the browser: https://developer.mozilla.org/en-US/docs/Web/CSS/white-space

div {
  white-space: pre-line;
}

<div>Foo
   Bar
       Baz     Foo
     Bar
 


     
  Baz
</div>

这篇关于将新行/n 转换为有角度的换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆