0

Can anybody tell how to search for a string in all properties. If match in some property I need to push the object in array in AngularJS.

I have an array

$scope.ListOfPeople = [
    { PersonID: 10, FirstName: "John", LastName: "Smith", Sex: "Male" },
    { PersonID: 11, FirstName: "James", LastName: "Last", Sex: "Male" },
    { PersonID: 12, FirstName: "Mary", LastName: "Heart", Sex: "Female" },
    { PersonID: 13, FirstName: "Sandra", LastName: "Goldsmith", Sex: "Female" },
    { PersonID: 14, FirstName: "Shaun", LastName: "Sheep", Sex: "Male" },
    { PersonID: 15, FirstName: "Nicola", LastName: "Smith", Sex: "Male" }
];

If the user types some value in search textbox. I need to search with PersonID, FirstName, LastName, Sex with all properties if it is match need to push the matched object.

4

2 Answers 2

2

I think Angular's Filter filter will do what you are looking for

<input ng-model="search"/>
<div ng-repeat="person in ListOfPeople | filter:search">
    {{person}}
</div>
Sign up to request clarification or add additional context in comments.

Comments

0

Something like that ?

for(var index in $scope.ListOfPeople) { 
   if ($scope.ListOfPeople.hasOwnProperty(index)) {
       if($scope.ListOfPeople[index] == "Your string") {
           // Do something here 
       }
   }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.