2

I have a data like below:

[
 { id: 1, name: 'test', point: '2000' }, 
 { id: 2, name: 'bob', point: '1000' },
 { id: 3, name: 'hello', point: '3000' },
 { id: 4, name: 'xx', point: '4000' },
 { id: 5, name: 'zz', point: '1000' },
 { id: 2, name: 'fad', point: '1000' }
]

How to filter it by different points dynamically but not statically :

<div ng-repeat="item in items | filter: { point: '1000' }"> 
<div ng-repeat="item in items | filter: { point: '2000' }"> 
Tss
  • 88
  • 4
  • 13

1 Answers1

0

You can create a point object on scope and update that in the controller and instead of the static value use the scope object instead.

Code For the same:

Controller:

app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';
  $scope.items = [
 { id: 1, name: 'test', point: '2000' }, 
 { id: 2, name: 'bob', point: '1000' },
 { id: 3, name: 'hello', point: '3000' },
 { id: 4, name: 'xx', point: '4000' },
 { id: 5, name: 'zz', point: '1000' },
 { id: 2, name: 'fad', point: '1000' }
]
$scope.pointToBeFiltered = '3000';
});

HTML:

 <body ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>
    <div ng-repeat="item in items | filter: { point: pointToBeFiltered }">{{item}}</div> 
  </body>

Working Plnkr

V31
  • 7,626
  • 3
  • 26
  • 44