Created
October 9, 2013 09:40
-
-
Save mohitmamoria/6898754 to your computer and use it in GitHub Desktop.
AngularJS Newline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- use it like this. Please notice that nohtml filter was used before newlines. --> | |
<p ng-bind-html-unsafe="post.content | nohtml | newlines"></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// to replace \n to <br/> | |
App.filter('newlines', function () { | |
return function(text) { | |
if(text) | |
return text.replace(/\n/g, '<br/>'); | |
return ''; | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// to escape html tags | |
App.filter('nohtml', function () { | |
return function(text) { | |
if(text) | |
return text | |
.replace(/&/g, '&') | |
.replace(/>/g, '>') | |
.replace(/</g, '<'); | |
return ''; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See https://stackoverflow.com/a/28537958/7304372 for escaping html