我正在使用 Angularjs
在我的应用程序中构建评论
功能。所以我在显示数据
时遇到问题。我从服务器获取数据如下:
This is the core collection of directives you would use in your template
code to build an AngularJS application.\n\nSome examples include: ngClick, ngInclude
数据包含\n
。它表示 new Line
。为了显示该数据,我使用 ng-bind-html
指令和 $sce.trustAsHtml(data);
。但数据显示在同一行中,而不添加新行。
谁能帮帮我吗?
最佳答案
默认情况下,HTML 中的空白会折叠起来。为了解决这个问题,您应该使用 <pre>
标签。 pre
内的空白区域不会折叠标签。
与 <p>
<p>
lots of text
with new lines
look like this
</p>
很多文字 有新线 看起来像这样
与 <pre>
<pre>
lots of text
with new lines
look like this
</pre>
lots of text with new lines look like this
引用:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre
关于javascript - 使用 Angular 显示内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24893825/