AngularJS filter Filter Last Updated : 01 Aug, 2022 Comments Improve Suggest changes Like Article Like Report The "filter" Filter in AngularJS is used to filter the array and object elements and return the filtered items. In other words, this filter selects a subset (a smaller array containing elements that meet the filter criteria) of an array from the original array. Syntax: {{arrayexpression | filter: expression : comparator : anyPropertyKey}} Parameter Values: arrayexpression: The source array on which the filter will be applied.expression: It is used to select the items from the array after the filter conditions are met. It can be of String type, Function type, or Object type.comparator: It is used to determine the value by comparing the expected value from the filter expression, and the actual value from the object array.anyPropertyKey: It is an optional parameter having the special property that is used to match the value against the given property. It is of String type & its default value is $.Example 1: This example describes the AngularJS filter Filter by filtering & rendering the name only having the character "e" in the name. HTML <!DOCTYPE html> <html> <head> <title>AngularJS filter Filter</title> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"> </script> </head> <body> <div ng-app="myApp" ng-controller="namesCtrl"> <h1 style="color:green;"> GeeksforGeeks </h1> <h3>AngularJS filter Filter</h3> <ol> <strong> <li ng-repeat="x in names | filter : 'e'"> {{ x }} </li> </strong> </ol> </div> <script> angular.module('myApp', []) .controller('namesCtrl', function($scope) { $scope.names = [ 'Jani', 'Carl', 'Margareth', 'Hege Mathew', 'Joey Tribiani', 'Gustav', 'Birgit', 'Mary', 'Kai' ]; }); </script> <p> This example displays the names containing the character "e"(filter) </p> </body> </html> Output: Example 2: This example uses an object to filter its element. HTML <!DOCTYPE html> <html> <head> <title> AngularJS filter Filter </title> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"> </script> </head> <body> <div ng-app="myApp" ng-controller="arrCtrl"> <h1 style="color:green"> GeeksforGeeks </h1> <h3> AngularJS filter Filter </h3> <ol> <li ng-repeat= "x in customers | filter :{'name' : 'e', 'city' : 'Patna'}"> {{x.name + ", " + x.city}} </li> </ol> </div> <p> The filter will give a match if there is an "e" character in the name, and the city is "Patna". Milk wasn't matched because the alphabet 'e' is not present. </p> <script> var app = angular.module('myApp', []); app.controller('arrCtrl', function ($scope) { $scope.customers = [{ "name": "Chocolate Shake", "city": "Patna" }, { "name": "Hot Chocolate", "city": "Delhi" }, { "name": "Milk", "city": "Patna" }, { "name": "Coffee", "city": "Patna" }, { "name": "Tea", "city": "Pune" }, { "name": "Mineral Water", "city": "Mumbai" }, { "name": "Iced Tea", "city": "Bangalore" }]; }); </script> </body> </html> Output: Example 3: In this example, we are going to see a "strict" caparison that does not return any value unless it is a pure match. HTML <!DOCTYPE html> <html> <head> <title> AngularJS filter Filter </title> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"> </script> </head> <body> <div ng-app="myApp" ng-controller="arrCtrl"> <h1 style="color:green"> GeeksforGeeks </h1> <h3> AngularJS filter Filter </h3> <ol> <li ng-repeat= "x in customers | filter : 'Chinchwad' : true"> {{x.name + ", " + x.city}} </li> </ol> </div> <p> The filter will give a match for the array item(s) where one or more object values are "Chinchwad". </p> <script> var app = angular.module('myApp', []); app.controller('arrCtrl', function($scope) { $scope.customers = [{ "name": "Mumbai Food", "city": "Chinchwad" }, { "name": "Gurgaon Catering", "city": "Haryana City" }, { "name": "Noida temperature", "city": " Chinchwad" }, ]; }); </script> </body> </html> Output: Note: If you notice that the last Chinchwad in the array is not included in the list, because the last Chinchwad contains space before itself. Reference: https://docs.angularjs.org/api/ng/filter/filter Comment More info S sanchit496 Follow Improve Article Tags : Web Technologies AngularJS AngularJS-Filter Explore AngularJS BasicsAngularJS Tutorial 5 min read Introduction to AngularJS 4 min read Angular CLI | Angular Project Setup 3 min read AngularJS Expressions 2 min read AngularJS Modules 3 min read AngularJS ng-model Directive 4 min read AngularJS Data Binding 4 min read AngularJS Controllers 3 min read AngularJS | Scope 2 min read AngularJS Services 4 min read AngularJS | AJAX - $http 3 min read AngularJS | Tables 2 min read AngularJS Select Boxes 2 min read AngularJS SQL 3 min read AngularJS HTML DOM 2 min read AngularJS Events 3 min read AngularJS | Forms 3 min read AngularJS Form Validation 3 min read AngularJS | API 2 min read AngularJS and W3.CSS 2 min read AngularJS Includes 3 min read AngularJS Animations 1 min read AngularJS | Application 3 min read AngularJS DirectivesAngularJS Directives 9 min read AngularJS ng-app Directive 1 min read AngularJS ng-bind Directive 2 min read AngularJS ng-bind-html Directive 2 min read AngularJS ng-bind-template Directive 2 min read AngularJS ng-blur Directive 1 min read AngularJS ng-change Directive 2 min read AngularJS ng-checked Directive 2 min read AngularJS ng-class Directive 2 min read AngularJS ng-class-even Directive 2 min read AngularJS ng-class-odd Directive 2 min read AngularJS ng-click Directive 2 min read AngularJS ng-cloak Directive 2 min read AngularJS ng-controller Directive 2 min read AngularJS Directives Complete Reference 2 min read AngularJS FiltersAngularJS | Filters 7 min read AngularJS currency Filter 2 min read AngularJS | date Filter 2 min read AngularJS filter Filter 3 min read AngularJS json Filter 2 min read AngularJS limitTo Filter 2 min read AngularJS lowercase Filter 1 min read AngularJS number Filter 1 min read AngularJS orderBy Filter 4 min read AngularJs uppercase Filter 1 min read AngularJS Converting FunctionsAngularJS angular.lowercase() Function 2 min read AngularJS angular.uppercase() Function 1 min read AngularJS angular.forEach() Function 1 min read AngularJS Comparing FunctionsAngularJS angular.isArray() Function 2 min read AngularJS angular.isDate() Function 2 min read AngularJS angular.isDefined() Function 2 min read AngularJS angular.isElement() Function 2 min read AngularJS angular.isFunction() Function 2 min read AngularJS angular.isNumber() Function 2 min read AngularJS angular.isObject() Function 2 min read AngularJS | angular.isString() Function 1 min read AngularJS angular.isUndefined() Function 2 min read AngularJS angular.equals() Function 2 min read AngularJS angular.toJson() Function 2 min read AngularJS QuestionsHow to bundle an Angular app for production? 4 min read How to add many functions in one ng-click directive? 2 min read How to directly update a field by using ng-click in AngularJS ? 3 min read How to Add Dynamic Options for Multiple Selects Inside ng-repeat Directive ? 3 min read How to detect when an @Input() value changes in Angular? 3 min read How to open popup using Angular and Bootstrap ? 2 min read How to reload or re-render the entire page using AngularJS? 2 min read How to add input fields dynamically on button click in AngularJS ? 2 min read How to Create Button Dynamically with Click Event in Angular ? 2 min read How to use jQuery in Angular ? 2 min read AngularJS Examples 2 min read Like