Rodrigo Zurek
Rodrigo Zurek

Reputation: 4575

Filter ng-repeat on Angularjs,

Im having trouble with a filter i have something like this:

<tr ng-repeat="data in dataset | filter:{id:12}">       
    <td>{{data.id}}</td>
    <td>{{data.name}}</td>
</tr>

i would to be able to filter by an array of ids something like this

id=[12,14,23]

and show the rows that have those ids

thanks for any help

Upvotes: 0

Views: 162

Answers (1)

holographic-principle
holographic-principle

Reputation: 19738

<tr ng-repeat="data in dataset | filter:filterFunction">       
    <td>{{data.id}}</td>
    <td>{{data.name}}</td>
</tr>

Controller:

$scope.filterFunction = function(data) {
  return $scope.filterValues.indexOf(data.id) !== -1 ? true : false;
};

$scope.filterValues = [12, 14, 23];

Upvotes: 2

Related Questions