javascript - How to filter ng-repeat data by time range? -


i'm creating app give flight list using third party api. have problem filtering between 2 time different date , time format, have gone thorough lot of tutorials there using date need filer using time different date , time format.

json

"combination": [             "outboundleg" :{             "departuredatetime": "07/14/2015 12:00"     }     "outboundleg" :{             "departuredatetime": "07/15/2015 10:55"     }     "outboundleg" :{             "departuredatetime": "07/18/2015 12:10"     }     "outboundleg" :{             "departuredatetime": "07/14/2015 10:10"     }     "outboundleg" :{             "departuredatetime": "07/18/2015 12:00"     } ] 

html

<div ng-repeat="data in combination | filterbtwntime: ??? ">     <td>{{data.outboundleg.departuredatetime}}</td>  </div> 

how achive this?

first data have not correct, since have object has same key, last value of outboundleg taken account. have array 1 object, has same key multiple times.

you need array of objects, because angular filters work on arrays.

the template:

<div ng-app="app">  <div ng-controller="mycontroller">      <div ng-repeat="data in combination | datefilter:startdate:enddate ">         <div ng-bind="data.departuredatetime "></div>      </div> </div> 

the filter:

function datefilter() {   return function(input, start, end) {     var inputdate = new date(input),         startdate = new date(start),         enddate = new date(end),         result = [];      (var i=0, len = input.length; < len; i++) {         inputdate = new date(input[i].departuredatetime);                     if (startdate < inputdate && inputdate < enddate) {            result.push(input[i]);         }       }            return result;          } } 

the full code can found in fiddle i've created small update on array, filter dates between start , end date defined. can adjust needed example.

fiddle - filter between 2 dates

update - filter on ng-repeat


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -