我怎么能preserve新行的角部分 [英] how can i preserve new lines in an angular partial

查看:126
本文介绍了我怎么能preserve新行的角部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个角的部分,我遍历条目列表如下:

Within an angular 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} 具有由角忽略了一些换行。我怎样才能使它preserve的换行符?

the content of {{entry.content}} have some line breaks which are ignored by angular. 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 code,你可以使用 NG-绑定-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']);

这篇关于我怎么能preserve新行的角部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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