Skip to content

Instantly share code, notes, and snippets.

@mohitmamoria
Created October 9, 2013 09:40
Show Gist options
  • Save mohitmamoria/6898754 to your computer and use it in GitHub Desktop.
Save mohitmamoria/6898754 to your computer and use it in GitHub Desktop.
AngularJS Newline
<!-- use it like this. Please notice that nohtml filter was used before newlines. -->
<p ng-bind-html-unsafe="post.content | nohtml | newlines"></p>
// to replace \n to <br/>
App.filter('newlines', function () {
return function(text) {
if(text)
return text.replace(/\n/g, '<br/>');
return '';
}
})
// to escape html tags
App.filter('nohtml', function () {
return function(text) {
if(text)
return text
.replace(/&/g, '&amp;')
.replace(/>/g, '&gt;')
.replace(/</g, '&lt;');
return '';
}
});
@chicken-suop
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment