将\ n替换为< br>标签角度6 [英] replace \n with <br> tag angular 6

查看:92
本文介绍了将\ n替换为< br>标签角度6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有rest api whit /n代码,可以用<br>标签替换角度6

i have rest api whit /n code, can angular 6 replace with <br> tag

这是我的代码:

{{x.deskripsi}}

我尝试使用 https://www.npmjs.com/package/angular-nl2br -过滤器

但是我不知道如何在{{}}标签内使用绑定

but i have no idea how to use with binding inside {{}} tag

我尝试使用此代码

<p ng-bind-html="x.deskripsi | nl2br"></p>

但不起作用

有什么帮助吗?

先感谢

推荐答案

您不需要库.只需将标签的white-space属性设置为pre-wrap(或使用默认情况下应具有此样式的<pre>标签)

You don't need a library. Simply set the white-space property of your tag to pre-wrap (or use a <pre> tag that should have this style by default)

document.querySelector('#formatted').innerText = 'Lorem\nIpsum';

#formatted {
  white-space: pre-wrap;
}

<div id="formatted"></div>
<div>Lorem\nIpsum</div>

这篇关于将\ n替换为&lt; br&gt;标签角度6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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