Trying to understand the “filter” function of AngularJS most of the examples have the filters on the view/HTML side but I need it on the controller/JS side.
This works
$scope.getPickedPeopleCount = function(){
var thisCount = 0;
angular.forEach($scope.allPeople, function(person){
if(person.PICKED){thisCount++}
});
return thisCount;
}
but this fails
$scope.getPickedPeopleCount = function(){
return $scope.allPeople.filter(PICKED:'true').length;
}
Obviously my syntax is wrong, can someone point me in the right direction
To use a filter in a controller, you must inject the $filter service and then request the filter by name: