[英]Display content by using angular
我正在使用Angularjs
在我的應用程序中構建comments
功能。 所以我在顯示data
遇到問題。 我從這樣的服務器獲取數據:
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
無需使用假設要格式化整個字符串的<pre>
,只需將"\\n"
替換為<br>
:
data.replace("\n","<br>");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.