preserve换行符在angularjs [英] Preserve line breaks in angularjs
问题描述
我见过<一个href=\"http://stackoverflow.com/questions/15449325/how-can-i-$p$pserve-new-lines-in-an-angular-partial\">this SO问题。
我的code,而不是 NG-绑定=item.desc
使用 {{} item.desc}
,因为我有一个 NG-重复
。
My code instead of ng-bind="item.desc"
uses {{item.desc}}
because I have a ng-repeat
before.
所以,我的code:
<div ng-repeat="item in items">
{{item.description}}
</div>
该项目描述中包含 \\ n
为其未呈现换行。
如何能在 {{} item.description}
显示轻易假设我有换行的 NG-重复
上面?
How can the {{item.description}}
display the newlines easily assuming that I have the ng-repeat
above?
推荐答案
尝试:
<div ng-repeat="item in items">
<pre>{{item.description}}</pre>
</div>
的&LT; pre&GT;
包装将打印文字与 \\ n
文本
The <pre>
wrapper will print text with \n
as text
我用 @保罗·韦伯
同意空格:pre-包装;
是更好的方法,反正使用&LT; pre&GT;
- 快捷方式主要用于调试一些东西(如果你不想把时间浪费在造型)
I agree with @Paul Weber
that white-space: pre-wrap;
is better approach, anyways using <pre>
- the quick way mostly for debug some stuff (if you don't want to waste time on styling)
这篇关于preserve换行符在angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!