angular-datetime-filter

AngularJS Datetime Filter

Angular Core Dependency: 1.2.x

Module License: MIT

Added by: Sam Deering

GitHub

Repository

djfarly/angular-datetime-filter

Stats

Stars: 5

Watchers: 5

Forks: 0

Module Description

angular-datetime-filter

AngularJS Datetime Filter

AngularJS filters for filtering arrays. The filters may be used just like the native filter-filter.

upcoming:date filters for array elements which date property is in the future.

past:date filters for array elements which date property is in the past.

##Install Install with bower:

bower install angular-datetime-filter

Add a <script> to you index.html:

<script src="/bower_components/angular-datetime-filter/dist/angular-datetime-filter.js"></script>

And add datetimeFilter as a dependency for your app:

angular.module('myApp', ['datetimeFilter']);

##How to use ###Array of objects

$scope.items = [
    {'date': '2014/01/02', 'name': 'one'},
    {'date': '2013/12/24', 'name': 'two'},
    {'date': '2014/10/03', 'name': 'three'},
    {'date': '2012/01/01', 'name': 'four'},
    {'date': '1970/01/01', 'name': 'five'}
];
<ul>
    <li ng-repeat="item in items | upcoming:date">{{item.name}}
</ul>

Assuming today is 2014/01/01; This should result in:

  • one
  • three

Whereas this:

<ul>
    <li ng-repeat="item in items | past:date">{{item.name}}
</ul>

Should result in:

  • two
  • four
  • five

###Simple datetime array

$scope.items = [
    '2014/01/02',
    '2013/12/24',
    '2014/10/03',
    '2012/01/01',
    '1970/01/01'
];
<ul>
    <li ng-repeat="item in items | upcoming">{{item}}
</ul>

Should result in:

  • 2014/01/02
  • 2014/10/03

Documentation

Angular module datetimeFilter

###upcoming

{{ filter_expression | upcoming : dateField }}
$filter('upcoming')(array, dateField)

array array - The source array

dateField string (optional) - the datetime property, defaults to none ###past

{{ filter_expression | past : dateField }}
$filter('past')(array, dateField)

array array - The source array

dateField string (optional) - the datetime property, defaults to none ###datetimeFilter

{{ filter_expression | datetimeFilter : dateField : mode }}
$filter('datetimeFilter')(array, dateField, mode)

array array - The source array

dateField string (optional) - the datetime property, defaults to none

mode string (optional) - Either 'past' or 'upcoming', defaults to 'upcoming'

Module stats last updated: 2015-06-07 05:25:39

Disclaimer: Some data on this page may have been gathered from the authors GitHub respository. If you see any mistakes or outdated information please let us know. Thanks!