convert new line /n to a line break in angular
This does not replace it, but you can use the CSS attribute white-space: pre-line;
to render the \n in the browser:https://developer.mozilla.org/en-US/docs/Web/CSS/white-space
1 - rewrite your filter next way:
.filter('textFormat', function() { return function (x) { return x.replace(new RegExp('\/n', 'g'), '<br/>'); } })
2 - in your html you should use the next syntax:
<span ng-bind-html="myOutput | textFormat"></span>
Where myOutput
is $scope.myOutput = ' Hello /n'
in Angular you can easy convert text to the original format by entering it like so:
component:
this.myText = 'This is line one\nThis is line 2\nAnd here is 3'
html:
<div [innerText]='myText'></div>