Custom Filters in AngularJS — a practical guide to AngularJS custom filters with clear examples you can reuse in real projects.
AngularJS Tutorial Series (39/99). Prefer one article? Read the complete AngularJS tutorial.
Short description
Keep filters pure/fast — they may run often during digests.
Custom filter
angular.module('myApp').filter('truncate', function () {
return function (value, limit) {
limit = limit || 20;
value = value || '';
return value.length > limit ? value.slice(0, limit) + '…' : value;
};
});