Creating Custom Filters

AngularJS enables you to create your own custom filter provider and then use it in expressions, controllers, and services as if it were a built-in filter. AngularJS provides the filter() method to create a filter provider and register it with the dependency injector server.

The filter() method accepts a name for the filter as the first argument and a function for the second argument. The filter function should accept the expression input as the first parameter and any additional parameters following that. For example:

filter('myFilter', function(){  return function(input, param1, param2){    return <<modified input>>;  };});

Inside the filter function you can change the value of the input ...

Get Learning AngularJS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.