更新时间:2023-12-04 13:40:10
它只是基本的 HTML.AngularJS 不会对此做出任何改变.您可以改用 pre
标签:
{{ entry.content }}
或者使用 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']);
Within an AngularJS partial I am looping over a list of entries as follows:
<ul class="entries">
<li ng-repeat="entry in entries">
<strong>{{ entry.title }}</strong>
<p>{{ entry.content }}</p>
</li>
</ul>
The content of {{entry.content}}
have some linebreaks which are ignored by AngularJS. How can I make it preserve the linebreaks?
It is just basic HTML. AngularJS won't change anything about that. You could use a pre
tag instead:
<pre>{{ entry.content }}</pre>
Or use CSS:
p .content {white-space: pre}
...
<p class='content'>{{ entry.content }}</p>
If entry.content
contains HTML code, you could use ng-bind-html
:
<p ng-bind-html="entry.content"></p>
Don't forget to include ngSanitize:
var myModule = angular.module('myModule', ['ngSanitize']);