var app = angular.module('app', []); app.controller('myController', function($scope) { $scope.friends = [ { "id": 0, "name": "Carroll Barr" }, { "id": 1, "name": "Carl Leni" }, { "id": 2, "name": "Bell Travis" }, { "id": 2, "name": "Yuyu Xia" } ]; //Example access to friendsAfterFilter, you dont really need this $scope.$watchCollection("friendsAfterFilter", function(newVal){ console.log("Hey, the filtered collection has changed!"); }); });
<div ng-app="app" ng-controller="myController"> Filter here: <input type="text" ng-model="search"> <ul> <li ng-repeat="friend in friendsAfterFilter = (friends | filter:search)"> {{ friend.name }} </li> </ul> <div> Number of filtered friends: {{friendsAfterFilter.length}} </div> </div>