I've been attempting to narrow down the data based on two specific dates, but I seem to be having trouble getting it to work correctly. Is there anyone out there who can lend a hand?
Here is my HTML:
<input type="date" ng-model="from_date">
<input type="date" ng-model="to_date">
And here is my ng-repeat:
<tr ng-repeat="item in outlets | dateRange:from_date:to_date">
<td>{{ item.offerID }}</td>
<td>{{ parseDate(item.startDate) | date:'yyyy-MM-dd' }}</td>
Lastly, here is my script:
app.filter('dateRange', function () {
return function (items, fromDate, toDate) {
var filtered = [];
console.log(fromDate, toDate);
var from_date = Date.parse(fromDate);
var to_date = Date.parse(toDate);
angular.forEach(items, function (item) {
if (item.startDate > from_date && item.startDate < to_date) {
filtered.push(item);
}
});
return filtered;
};
});
Here is some sample JSON data from the server:
{
"offerID": "1"
, "merchant": "Rifa Ladies Salon"
, "outelt": "Rifa Ladies Salon Business Bay"
, "offer": "Rifa Ladies Salon- Offer 1"
, "offerStatus": "LIVE"
, "startDate": "2016-07-12"}