UPDATE: I think that I actually didn’t look at the documentation enough, but you can definitely use filter with this syntax (see this fiddle ) to filter by the property of the objects:
<tr ng-repeat="user in users | filter:{status:4}">
Here is my original answer if it helps someone:
Using the filter filter , you cannot pass a parameter, but you can do at least two things.
1) Set the data that you want to filter in a variable scope and specify what is in your filter function, for example, this fiddle .
JavaScript:
$scope.status = 1; $scope.users = [{name: 'first user', status: 1}, {name: 'second user', status: 2}, {name: 'third user', status: 3}]; $scope.isStatus = function(user){ return (user.status == $scope.status); };
Html:
<li ng-repeat="user in users | filter:isStatus">
OR
2) Create a new filter that takes a parameter to this script .
JavaScript:
var myApp = angular.module('myApp', []); myApp.filter('isStatus', function() { return function(input, status) { var out = []; for (var i = 0; i < input.length; i++){ if(input[i].status == status) out.push(input[i]); } return out; }; });
Html:
<li ng-repeat="user in users | isStatus:3">
Note that this filter assumes that there is a status property in array objects that can make it less reusable, but this is just an example. You can read this for more information on creating filters.
Gloopy Aug 16 2018-12-12T00: 00Z
source share