Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular filter by multiple properties and show if any value is equal to search

When using ng-repeat I want to filter object by two values (name and description). I want to filter this array in way if in any key exists value in search it will return it. When I'm trying this filter:{info:{name:search, description:search}} the result is when value from search equals in both.

like image 938
Przemek Avatar asked Jan 29 '26 22:01

Przemek


1 Answers

Okay so based on what I have been able to understand. Although I am not sure if this is what you wanted, if not let me know and I will delete this answer.

Let's say you have object that has values in this format which you are feeding to ng-repeat.

  $scope.inputobject = [
    {name: 'xyz', description: 'hadhash'},
    {name: 'uza', description: 'hadhahdh'},
    {name: 'aaa', description: 'hadhahas'}  
  ];

This is our HTML part now, add the controller and all, I hope that wont be a problem.

<input type="text" placeholder="search" ng-model="objectsearch">
<div ng-repeat="x in inputobject | filter:{name:objectsearch}">
<div>
{{x.name}} {{x.lastname}}
</div>
</div>

Now filter will only happen based on first input. Cheers!

like image 116
Gandalf the White Avatar answered Jan 31 '26 18:01

Gandalf the White



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!