Explain custom filters with an example.

bookmark

We can create our own filters in AngularJS. It can be performed by associating the filter to our module. These types of filters are known as custom filters.

An example given below can be used to count the number of elements in the string by using the filter:

angular.module('myCountFilterApp', [])  
   .filter('count',function()  
{  
    return(function(input)  
    {  
        var out=[];  
        out=input.split(',');  
        return out.length;  
    })  
});  
As per above example, if the string is "21, 34, 45" then output after applying filter will be 3.