Chapter 2: Creating custom search filters

by billy roberts

HTML

<script src="https://code.angularjs.org/1.3.2/angular.min.js"></script>
<div ng-app="myApp">
    <div ng-controller="Ctrl">
        <input ng-model="search.lastName" />
        <p ng-repeat="user in users | filter:search">
            {{ user.firstName}} {{ user.lastName }}
        </p>
    </div>
</div>

JavaScript

// display both names, only search the last name

angular.module('myApp', [])
.controller('Ctrl',function($scope) {
    $scope.users = [
        { 
            firstName: 'John',
            lastName: 'Stockton'
        },
        {
            firstName: 'Michael',
            lastName: 'Jordan'
        }
    ];
});