如何在AngularJS部分中保留换行? [英] How can I preserve new lines in an AngularJS partial?

查看:100
本文介绍了如何在AngularJS部分中保留换行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在AngularJS部分中,我如下遍历条目列表:

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>

{{entry.content}}的内容具有一些换行符,AngularJS会忽略这些换行符.如何保存换行符?

The content of {{entry.content}} have some linebreaks which are ignored by AngularJS. How can I make it preserve the linebreaks?

推荐答案

这只是基本的HTML. AngularJS不会对此进行任何更改.您可以改用pre标记:

It is just basic HTML. AngularJS won't change anything about that. You could use a pre tag instead:

<pre>{{ entry.content }}</pre>

或使用CSS:

p .content {white-space: pre}

...

<p class='content'>{{ entry.content }}</p>

如果entry.content包含HTML代码,则可以使用ng-bind-html:

If entry.content contains HTML code, you could use ng-bind-html:

<p ng-bind-html="entry.content"></p>

别忘了包含 ngSanitize :

var myModule = angular.module('myModule', ['ngSanitize']);

这篇关于如何在AngularJS部分中保留换行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆