Angular Search for value in JSON and display corresponding data Angular Search for value in JSON and display corresponding data angularjs angularjs

Angular Search for value in JSON and display corresponding data


The key is just to iterate over the data object while observing the correct structure for accessing the values.

Your search function could look like this:

$scope.results = [];$scope.findValue = function(enteredValue) {         angular.forEach($scope.myData.SerialNumbers, function(value, key) {        if (key === enteredValue) {            $scope.results.push({serial: key, owner: value[0].Owner});        }    });};

Notice that I'm pushing the results into an array. You can setup an ng-repeat in the view which will use this to present a live view of the results:

<input type="text" ng-model="enteredValue"><br><button type="button" ng-Click="findValue(enteredValue)">Search</button><h3>Results</h3><ul>    <li ng-repeat="result in results">Serial number: {{result.serial}}    | Owner: {{result.owner}}</li></ul>

Demo