-
-
Save joshorvis/10217220 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.filter('daterange', function () { | |
return function(items, date_field,start_date, end_date) { | |
var result = []; | |
// date filters | |
var start_date = (start_date && !isNaN(Date.parse(start_date))) ? Date.parse(start_date) : 0; | |
var end_date = (end_date && !isNaN(Date.parse(end_date))) ? Date.parse(end_date) : new Date().getTime(); | |
// if the items are loaded | |
if (items && items.length > 0) { | |
angular.forEach(items, function (index, item) { | |
var itemDate = new Date(item['date_field']); | |
if (itemDate >= start_date && itemDate <= end_date) { | |
result.push(item); | |
} | |
}); | |
return result; | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just a note, in line 11, with function (index, item) it should be function(item, index).
https://docs.angularjs.org/api/ng/function/angular.forEach
angular.forEach(values, function(value, key))