I am trying to filter the data between two dates. I was trying to fix it but I could not complete it. Can anyone help me?
My html:
<input type="date" ng-model="from_date">
<input type="date" ng-model="to_date">
My ng-repeat:
<tr ng-repeat="item in outlets | dateRange:from_date:to_date">
<td></td>
<td></td>
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;
};
});
jason data from 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"}
Source: AngularJS
from Angular Questions https://angularquestions.com/2017/09/25/custom-filter-between-two-dates/
via @lzomedia #developer #freelance #web
No comments:
Post a Comment