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

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -