I'm starting with Angular JS and I'm stuck with a problem. I have the following function in the controller that applies a filter to a ng-repeat of a table.
$scope.dateRangeFilter = function (property, startDate, endDate) {
if (startDate==null)
{
startDate=moment('1900-01-01',"YYYY-MM-DD");
var s=moment(startDate,"YYYY-MM-DD");
}
else
{
var datestart = new Date(startDate);
var s=moment(datestart.getFullYear() + '/' + ("0" + (datestart.getMonth() + 1)).slice(-2) + '/' + datestart.getDate() ,"YYYY-MM-DD");
}
if (endDate==null)
{
endDate=moment('2999-31-12',"YYYY-MM-DD");
var e=moment(endDate,"YYYY-MM-DD");
}
else
{
var datend = new Date(endDate);
var e=moment(datend.getFullYear() + '/' + ("0" + (datend.getMonth() + 1)).slice(-2) + '/' + datend.getDate() ,"YYYY-MM-DD");
}
return function (item) {
if (item[property] === null) return false;
var itemDate = moment(item[property]);
if (itemDate >= s && itemDate <= e) return true;
return false;
}
}
Then I apply it in ng-repeat
<tr ng-repeat="user in plazas | filter: dateRangeFilter('date', fechaDesde, fechahasta)">
What I need is to be able to apply that same filter to the controller because I need to get the number of records with filters for other functionality.
$scope.getData = function () {
return $filter('filter')($scope.plazas, ..............................)
}
Any ideas please? Thank you very much