用 <br> 替换 \n标记角度 6 [英] Replace \n with <br> tag angular 6
本文介绍了用 <br> 替换 \n标记角度 6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有 \n
作为反斜杠标签的 REST API,angular 6 可以用 <br>
标签替换它们吗?
这是我的代码:
{{x.deskripsi}}
我尝试使用这个包,但我不知道如何将其与 {{}}
标签内的绑定一起使用.我尝试使用
<p ng-bind-html="x.deskripsi |nl2br">/p>
但它不起作用.有什么帮助吗?
提前致谢.
解决方案
您不需要库.只需将标签的 white-space
属性设置为 pre-wrap
(或使用应该具有此样式的
标签)默认)document.querySelector('#formatted').innerText = 'Lorem\nIpsum';
#formatted {空白:预包装;}
<div id="formatted"></div><div>Lorem\nIpsum</div>
I have a REST API with
\n
as backslash tags, can angular 6 replace these with<br>
tags?Here's my code:
{{x.deskripsi}}
I try to use this package, but I have no idea how to use it with binding inside a
{{}}
tag. I tried using<p ng-bind-html="x.deskripsi | nl2br"></p>
but it doesn't work. Any help?
Thanks in advance.解决方案You don't need a library. Simply set the
white-space
property of your tag topre-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>
这篇关于用 <br> 替换 \n标记角度 6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文