简体   繁体   中英

ng-repeat date range filter

I am using ng-repeat to bind data with a filter for name search:

<div ng-repeat='myoldrecs in myoldrec | filter:q as results '>......</div>
$scope.myoldrec = [{name:ccc,date:13-02-2016},{name:ddd,date:14-02-2016}];
<input type="search" ng-model="q" placeholder="filter contacts..." class='form-control' style='width: 95%;'/>

No problem up to this point, its working fine. After this, I need to add one more filter by date range (start date and end date).

After adding the second filter:

<div ng-repeat='myoldrecs in myoldrec | filter:q as results |  myfilter:date1:date2 '>......</div>

Above text boxes have date, but its giving an error:

alias 'results | myfilter:date1:date2' is invalid --- must be a valid JS identifier which is not a reserved name.

I need to find solution to add the second filter and compare two date ranges. In my case the date is not in JSON, it's in normal date format eg: 10-02-2016.

Finally, i came with one solution to filter date range between two dates, instead of using more filter just convert the string date to date object and use if statement to greater than or less than operators.Still its, working fine for me.

<div ng-if="convertdateobj(data.timconverted) >= frmdate && convertdateobj(data.timconverted) <= todate">
   <!--ng-if="convertdateobj(data.timconverted) >= frmdate && data.timconverted <= todate" -->
 <table>
<tr><td>{{data.label0}} - </td><td>{{data.value0}} - </td><td>{{data.timeadded}}</td></tr>

</table>
</div>

Controller

$scope.convertdateobj = function(mydte){return new Date(mydte);});

Also,above plunker link(my last comment) has updated to this solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM