Prev Demo
AngularJS
>
Custom Filter Function
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" /> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> </head> <script> var members = [ { username: 'SheoNarayan', address: 'Hyderabad', pin : '500049' }, { username: 'Munna', address: 'Bokaro', pin: '8256598' }, { username: 'Jay', address: 'Aurangabad', pin: '824101' }, { username: 'Sreeni', address: 'New York', pin: 'BY-524' } ]; var app = angular.module("app", []); app.controller("ListController", ["$scope", function ($scope) { $scope.Members = members; // custom filter function $scope.FilterFunction = function (item) { return (item.pin.indexOf('BY') >= 0); }; }]); </script> <body> <div ng-app="app" ng-controller="ListController"> <h3>Filtering using custom filter function</h3> <table class="table"> <tr> <th>UserName</th> <th>Address</th> <th>PIN</th> </tr> <tr ng-repeat="member in Members | filter:FilterFunction"> <td>{{member.username}}</td> <td ng-bind="member.address"></td> <td>{{member.pin}}</td> </tr> </table> </div> </body> </html>
Note: We DO NOT save your trial code in our database.
Output