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?
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.
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:
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With