angularjs - 如何在 AngularJS 部分中保留新行?

标签 angularjs

在 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/

相关文章:

angularjs - d3 驱动的指令转换在 ng-repeat 中不起作用

angularjs - 使用$ compileProvider.debugInfoEnabled(false);从DOM元素获取范围。

javascript - 谷歌图表巨大的组织图离开屏幕

angularjs - Angular ui-router subview 问题

javascript - 为什么我的 AngularJS Controller 定义和标记没有按预期工作? - <controller> 不是函数错误

javascript - $scope 变量在指令隔离范围内未定义

AngularJS - 类型错误 : Cannot read property X of undefined

JavaScript 单元测试 : Cannot check if jQuery method was called

javascript - 在 angularjs 中生成 javascript

angularjs - 集成 ASP.NET Web 窗体、Web API 和 AngularJS