javascript - 使用 Angular 显示内容

标签 javascript angularjs

我正在使用 Angularjs 在我的应用程序中构建评论功能。所以我在显示数据时遇到问题。我从服务器获取数据如下:

    This is the core collection of directives you would use in your template 
code to build an AngularJS application.\n\nSome examples include: ngClick, ngInclude

数据包含\n。它表示 new Line。为了显示该数据,我使用 ng-bind-html 指令和 $sce.trustAsHtml(data);。但数据显示在同一行中,而不添加新行。

谁能帮帮我吗?

最佳答案

默认情况下,HTML 中的空白会折叠起来。为了解决这个问题,您应该使用 <pre>标签。 pre 内的空白区域不会折叠标签。

<p>

<p>
lots of text 
with new lines 
look like this
</p>

很多文字 有新线 看起来像这样

<pre>

<pre>
lots of text 
with new lines 
look like this
</pre>
lots of text 
with new lines 
look like this

引用:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre

关于javascript - 使用 Angular 显示内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24893825/

相关文章:

javascript - 带有 ng-class 的 Angular JS 指令

javascript - 在 javascript 中创建具有随机二进制值 (0,1) 的数组

javascript - 如何在 Vue 组件中使导出的变量具有反应性?

html - 文本未与相应的复选框对齐

javascript - AngularJS 自定义指令中的自定义过滤器

javascript - 在 Angular JS Promise 中没有获取状态错误代码

javascript - 如何在 React Router v4 中向子进程发送 props?

javascript - 社交媒体图标之间的间距

javascript - $rootScope.$emit 和 $on

javascript - Angular UI Router - 子状态的解析始终等待父状态解析