user3731438
user3731438

Reputation: 283

AngularJS - For loop to push whole object than just title

I have created a plunkr here: http://plnkr.co/edit/wPCex3lJc5E0I4fSeXI1?p=preview

The application should allow the user to perform a search, and return results.

I have got to the point where the number of correct results are shown (if just a country is selected), but i cant seem to pass the whole matching object in my for loop.

HTML:

<div ng-repeat="myresults in Results track by $index">

    {{myresults}}

</div>

JS:

$scope.Results = [];  

$scope.search = function(country, city, department) {
    var countryValue = country.Country;
    for (i = 0; i < $scope.Data.length; i++) {

      if ($scope.Data[i].Country == countryValue) {
        $scope.Results.push(countryValue);
      }
    }

    console.log($scope.Results);
  }

Upvotes: 0

Views: 409

Answers (1)

plalx
plalx

Reputation: 43728

You are only pushing the country name in $scope.Results, push the whole data object instead:

$scope.Results.push($scope.Data[i]);

http://plnkr.co/edit/DH8DBUKoWKITIyaEH1yD?p=preview

Upvotes: 1

Related Questions