Reputation: 2276
I am Building comments
feature in my application by using Angularjs
. So I have a problem in displaying the data
. I am getting data from server like this:
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
the data contains \n
. it indicates new Line
.For displaying that data I am using ng-bind-html
directive with $sce.trustAsHtml(data);
. But data is displaying in same line not added new lines.
Can any one Help me Please.
Upvotes: 1
Views: 28
Reputation: 3651
Instead of using <pre>
which assumes you want to format the entire string, you can simply replace "\n"
with <br>
:
data.replace("\n","<br>");
Upvotes: 0
Reputation: 3651
By default whitespace is collapsed within HTML. To get around that, you should use a <pre>
tag. White space will no be collapsed within a pre
tag.
<p>
<p>
lots of text
with new lines
look like this
</p>
lots of text with new lines look like this
<pre>
<pre>
lots of text
with new lines
look like this
</pre>
lots of text with new lines look like this
Reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre
Upvotes: 1