Jojo
Jojo

Reputation: 403

How to filter data inside an ng-repeate using the ng-repeat value

I need to filter some data according to the value I get from ng-repeate. my html looks like this. I need to display the data from other scope object($scope.allData) by filtering using the value

<div ng-repeat="value in selectedIds">
    <h6>Id</h6>{{}} <br/>
    <h6>Name</h6>{{}} <br/>
    <h6>Age</h6>{{}} <br/>

   </div>

and my controller look like

app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';

  $scope.selectedIds=[{id:"123"},{id:"124"},{id:"125"},{id:"126"}];
  $scope.allData=[{id:"123",name:"James",age:"21"},
  {id:"124",name:"James",age:"21"},
  {id:"125",name:"Frank",age:"22"},
  {id:"126",name:"John",age:"24"},
  {id:"127",name:"Jimmy",age:"26"},
  {id:"128",name:"Ann",age:"61"},
  {id:"129",name:"Mark",age:"41"},
  {id:"130",name:"Lach",age:"33"}
  ];
});

I create the the plunker

Upvotes: 0

Views: 140

Answers (1)

Arun AK
Arun AK

Reputation: 4370

you can use filter in your ng-repeat function.

<body ng-controller="MainCtrl">
   <div ng-repeat="value in selectedIds">
      <div ng-repeat="values in allData | filter: value.id">
         <h6>Id</h6>{{values.id}} <br/>
         <h6>Name</h6>{{values.name}} <br/>
         <h6>Age</h6>{{values.age}} <br/>
      </div>
   </div>
</body>

Hope it works in your case. here is the working link

Upvotes: 1

Related Questions