Skip to content

Instantly share code, notes, and snippets.

@neilmaledev
Last active September 22, 2016 05:32
Show Gist options
  • Save neilmaledev/54c41b04c0fd4546eb930f97ec89987d to your computer and use it in GitHub Desktop.
Save neilmaledev/54c41b04c0fd4546eb930f97ec89987d to your computer and use it in GitHub Desktop.
i just modified the one that is here http://stackoverflow.com/questions/27064319/angularjs-limitto-using-html-tags. I added auto ellipsis
.filter('limitHtml', function() {
return function(text, limit) {
var changedString = String(text).replace(/<[^>]+>/gm, '');
var length = changedString.length;
return changedString.length > limit ? changedString.substr(0, limit) + '...' : (changedString == 'null' ? '' : changedString);
};
})
@neilmaledev
Copy link
Author

usage:

<div ng-bind-html="news.description | limitHtml: 100">

with auto ellipsis "..." if char length exceeds the limit

@neilmaledev
Copy link
Author

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