Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
AngularJS

Custom Filters in AngularJS

Register filters that return a transform function.

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;
  };
});

Leave a reply

Your email address will not be published. Required fields are marked *