Passing arguements to filters in Angular.js

In Angular.js filters can be added to format data. There are currency, date, filter, json and few other filters which are used to format the data. The filter Filter selects a subset of an array and it can only be used on arrays. It returns the resultant array which contains matching items. To filter the data using any name you have to pass the arguments to the filter function. You can also use angular’s native ‘filter’ filter and pass arguments to your custom filter.

Consider this custom filter below:

$scope.weDontLike =function(item, name) {

console.log(arguments);

return item.name!= name;

};

Now take a look at the below code.

<div ng-repeat="group in groups">

<ling-repeat="friend in friends | filter:weDontLike(group.enemy.name)">

<span>{{friend.name}}</span>

<li>

</div>

To make the filter work. You have to change it as given below.


$scope.weDontLike =function(name) {

return function(friend) {

return friend.name != name;

}

}

The original item comes from the filter and the weDontLike returns another function.