Skip to content

Instantly share code, notes, and snippets.

@davutg
Last active November 1, 2016 19:18
Show Gist options
  • Save davutg/40fa1ac4481a9d1fe27db4816386d45e to your computer and use it in GitHub Desktop.
Save davutg/40fa1ac4481a9d1fe27db4816386d45e to your computer and use it in GitHub Desktop.
Escape html tags filter for angular 1.x
myApp.filter('escapeHtml', function () {
var entityMap = {
"&": "&",
"<": "&lt;",
">": "&gt;",
'"': '&quot;',
"'": '&#39;',
"/": '&#x2F;'
};
return function (str) {
return String(str).replace(/[&<>"'\/]/g, function (s) {
return entityMap[s];
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment