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']);

Leave a Comment