javascript - Angular `ng-repeat` - how to filter only two properties? -


at moment, have search box , repeat list. repeat list uses object many properties.

json

$scope.userlist = [{   firstname: "jack",   lastname: "smith",   description: "this description" }, {   firstname: "luke",   lastname: "mcdonald",   description: "my name luke, , friend jack" }] 

and repeat list:

<md-list-item ng-repeat="user in userlist | filter: searchinput allresults">   <p>{{user.firstname}} {{user.lastname}}</p> </md-list-item> 

my search boxes model searchinput, , object saved scope $scope.userlist.

if search jack, both results displayed due both objects containing search term.

how can limit filter within firstname , lastname properties?

use in controller

$scope.searchfilter = function (user) {     var keyword = new regexp($scope.searchinput, 'i');     return !$scope.searchinput || keyword.test(user.firstname) || keyword.test(user.lastname); } 

and html be:

<md-list-item ng-repeat="user in userlist | filter: searchfilter">  <p>{{user.firstname}} {{user.lastname}}</p> </md-list-item> 

Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -