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

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

问题描述

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

    <li ng-repeat="进入条目"><strong>{{ entry.title }}</strong><p>{{ entry.content }}</p>

{{entry.content}} 的内容有一些被 AngularJS 忽略的换行符.我怎样才能让它保留换行符?

解决方案

它只是基本的 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']);

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

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