Within Angular, I need to generate a series of paragraph elements from a block of text containing newline characters?
I can think of a couple of ways to do this. Ho
var myApp = angular.module('myApp', ['ngSanitize']);
myApp.controller('myCtrl', function($scope){
$scope.myText = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\nSed diam nonummy nibh euismod tincidunt ut laoreet dolore.\nMagna aliquam erat volutpat. Ut wisi enim ad minim veniam."
});
myApp.filter('nl2p', function () {
return function(text){
text = String(text).trim();
return (text.length > 0 ? '' + text.replace(/[\r\n]+/g, '
') + '
' : null);
}
});
http://jsfiddle.net/moderndegree/934aZ/