I have a scenario. I have a comment box for the users where they can put comments with new line like:
This is my comment.
Part of comment in new line
I am saving in database as :
model.Description = model.Comment.Replace("\n", "<br />");
//Insert into DB
Now while showing it on AngularJs View, it is showing something like:
This is my comment. <br /> Part of comment in new line
**My html : **
<style>
.angular-with-newlines {
white-space: pre;
}
</style>
<div class="ads-details-info col-md-8 angular-with-newlines">
{{comment}}
</div>
Output:
123123123123 \n 123123123123 <br /> 123123123123 \\n
I want to render <br />
as new line. I know there are some solutions available like: trustAsHtml
and ng-bind-html
. But then it becomes vulnerable to XSS
attack. Which I don't want. I want to allow only some selected tags. Is there any solution available?
I have seen Preserve line breaks in angularjs . But solutions did not work for me. I don't want comment to be rendered as code and white-space: pre; did not work for me.
with \n but did not work. \n is rendered as it is. – Usman Khalid Sep 04 '15 at 15:21
, \n, \\n .. – Usman Khalid Sep 04 '15 at 15:26