在 AngularJS 部分中,我循环访问条目列表,如下所示:
<ul class="entries">
<li ng-repeat="entry in entries">
<strong>{{ entry.title }}</strong>
<p>{{ entry.content }}</p>
</li>
</ul>
{{entry.content}}
的内容有一些被 AngularJS 忽略的换行符。我怎样才能让它保留换行符?
最佳答案
这只是基本的 HTML。 AngularJS 不会对此做出任何改变。您可以使用 pre
标签代替:
<pre>{{ entry.content }}</pre>
或者使用CSS:
p .content {white-space: pre}
...
<p class='content'>{{ entry.content }}</p>
如果entry.content
包含HTML代码,您可以使用ng-bind-html
:
<p ng-bind-html="entry.content"></p>
不要忘记包含 ngSanitize :
var myModule = angular.module('myModule', ['ngSanitize']);
关于angularjs - 如何在 AngularJS 部分中保留新行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15449325/