Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is dateFilter and where can I find out more about it?

Tags:

I am going through the Angular documentation on directives: http://docs.angularjs.org/guide/directive

One of the examples on the page (full working example here http://jsbin.com/osOQOYag/3/edit?html,js,output

angular.module('docsTimeDirective', [])   .controller('Ctrl2', function($scope) {     $scope.format = 'M/d/yy h:mm:ss a';   })   .directive('myCurrentTime', function($interval, dateFilter) {      function link(scope, element, attrs) {       var format,           timeoutId;        function updateTime() {         element.text(dateFilter(new Date(), format));       }        scope.$watch(attrs.myCurrentTime, function(value) {         format = value;         updateTime();       });        element.on('$destroy', function() {         $interval.cancel(timeoutId);       });        // start the UI update process; save the timeoutId for canceling       timeoutId = $interval(function() {         updateTime(); // update DOM       }, 1000);     }      return {       link: link     };   }); 

On the line:

.directive('myCurrentTime', function($interval, dateFilter) { 

I cannot for the life of me find any information on the .directive prototype and cannot find any documentation on dateFilter anywhere either. Also, I know that dateFilter is found in the un-minified version of AngularJS (although the name disappears in the minified version). Can anyone provide some guidance (and possibly a link) explaining more about dateFilter and similar functions?

like image 343
Mike Cheel Avatar asked Dec 26 '13 17:12

Mike Cheel


People also ask

How do I use templated filters to refer to dates?

You can use templated filters to refer to dates by selecting the beginning and end dates in a date filter — {% date_start date_filter %} and {% date_end date_filter %}, respectively. This article will walk you through some use cases examples and the steps to accomplish them.

Why does my date_start date_filter fail?

Note that this will still fail for filters for dates from before the earliest date in the dataset because {% date_start date_filter %} will evaluate to NULL . It is also possible to use COALESCE or IFNULL to encode a default set of tables to query. In the example below, the past two months are used:

How to filter data by date in Excel?

There is another combination function that we can use to filter data by date in Excel. They are the FILTER, MONTH & YEAR functions. Here, we’ll filter the sales for February and the Year- 2015. Press the Enter button to get the filtered sales.

How do I filter dates in fetchxml?

One great option in FetchXML is to filter dates using a relative filter such as “this week”, “older than 2 years” etc. This is particularly helpful when you build a view, as it will automatically build the date criteria each time so your view is always up to date.


1 Answers

Date filter docs are here: http://code.angularjs.org/1.2.5/docs/api/ng.filter:date

Here's part of the docs that explain filter injection: http://code.angularjs.org/1.2.5/docs/guide/filter#using-filters-in-controllers-and-services

Filters are usually used in view expressions ({{myDate | date:'short'}}), but they can also be used in your JS code. Filters are injected by appending string Filter to the filter name (e.g. date -> dateFilter).

app.controller('MyCtrl', function($scope, dateFilter, lowercaseFilter){   $scope.myDate = new Date();   $scope.myDateFormatted = dateFilter($scope.myDate, 'shortDate');    $scope.myString = 'Some String';   $scope.myStringLowerCased = lowercaseFilter($scope.myString); }); 

PLUNKER

like image 61
Stewie Avatar answered Oct 30 '22 12:10

Stewie