How can I preserve new lines in an AngularJS partial?
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']);
I make filters
// filters js
myApp.filter("nl2br", function($filter) {
return function(data) {
if (!data) return data;
return data.replace(/\n\r?/g, '<br />');
};
});
then
// view
<div ng-bind-html="article.description | nl2br"></div>
I fix it by adding pre-line
:
<style>
pre{
white-space: pre-line;
}
</style>
My data:
<pre>{{feedback.Content}}<pre>