6

i am new in angular and i am bit familiar with filter word but what is filterFilter word and usage in angular. just come across a code below from this url https://stackoverflow.com/a/22704140/6188148.

see the code

angular.module('FilterInControllerModule', []).
    controller('FilterController', ['filterFilter', function(filterFilter) {
      this.array = [
        {name: 'Tobias'},
        {name: 'Jeff'},
        {name: 'Brian'},
        {name: 'Igor'},
        {name: 'James'},
        {name: 'Brad'}
      ];
      this.filteredArray = filterFilter(this.array, {name:'Igor'});
    }]);

just tell me what is filterFilter ? is it any built-in filter ?

Community
  • 1
  • 1
Thomas
  • 33,544
  • 126
  • 357
  • 626

2 Answers2

9

Every filter can be injected as a service, whose name is <theNameOfTheFilter>Filter.

So, for example, if you want to use the uppercase filter from a controller (for example), you can do

module.controller('MyController', function($scope, uppercaseFilter) {
    $scope.foo = uppercaseFilter('hello');
});

Your code does the same thing, with the filter filter.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
3

Angular filter names just have to end with Filter in order to be a valid filter.

Reto
  • 1,305
  • 1
  • 18
  • 32